Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
round($number,2)phpの関数を使用して、 a$numberを最も近い 100 分の 1 に丸めています。うまく機能しますが、100 番目の小数点が に等しい場合、 は0表示されません0。読むには番号が必要です:
round($number,2)
$number
0
1.70
いいえ
1.7
これを達成するための良い方法を知っている人はいますか?1ページに約20個の数字でやっています。どんな助けでも大歓迎です!
数字をパディングする必要があります。次のようなものが機能します。
number_format((float)$number, 2, '.', '');
使用sprintf():
sprintf()
echo sprintf('%.2f', 1.7);
ショー:
<?php $number = 1.7; $number = sprintf("%0.2f",$number); echo $number; ?>
出力