金額表記を行う際に金額を3桁ずつ区切りたい時など、PHPで数値を3桁ごとにカンマ(,)で区切る方法。
詳細は以下から。
今回は『number_format()関数』を用います。
//第二引数の指定無し $hoge = 1000000; echo number_format($hoge); //表示結果は『1,000,000』 $hoge = 1000000.5; echo number_format($hoge); //表示結果は『1,000,001』(小数点以下繰り上げ) //第二引数の指定 $hoge = 1000000; echo number_format($hoge, 2); //表示結果は『1,000,000.00』 $hoge = 1000000.5; echo number_format($hoge, 2); //表示結果は『1,000,000.50』