0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP-数値を3桁ごとにカンマを付与する関数

Posted at

number_format関数

数字を千位毎にグループ化してフォーマットする

<?php
  echo number_fornmat(1234567); //1,234,567

laravelで使うときは下記のような感じで使う

$price = [1000, 2000, 3000,];
foreach ($price as $value){
<td>¥{{ number_format($value->price) }}</td>
}

結果
¥1,000
¥2,000
¥3,000

余談ですが、勝手に小数点を含む数値」を四捨五入するので、第二引数に桁数を指定すれば小数点以下も表示できます。

<?php
  echo number_format(1234.567,2); // 1,234.57
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?