LoginSignup
0
0

More than 3 years have passed since last update.

[PHP] 3桁ごとに数値にカンマを挿入する

Posted at

概要

金額を表示するために3桁ごとにカンマで区切りたい場合、
PHPだと関数一つで簡単に実現することができます。

例)1000000 → 1,000,000

方法

  • number_format()を使う
<?php
    $num = 1000000;

    $result = number_format($num);

    print_r($result);
?>

//結果:1,000,000

文字列でも可能です。

<?php
    $str = '1000000';

    $result = number_format($str);

    print_r($result);
?>

//結果:1,000,000
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0