概要
金額を表示するために3桁ごとにカンマで区切りたい場合、
PHPだと関数一つで簡単に実現することができます。
例)1000000 → 1,000,000
方法
- number_format()を使う
.php
<?php
$num = 1000000;
$result = number_format($num);
print_r($result);
?>
//結果:1,000,000
文字列でも可能です。
.php
<?php
$str = '1000000';
$result = number_format($str);
print_r($result);
?>
//結果:1,000,000