PHPの文字列を小数点以下2桁に丸めるにはどうしたらいいですか?
$number = "520"; // It's a string from a database
$formatted_number = round_to_2dp($number);
echo $formatted_number;
出力は 520.00
となるはずです。
関数 round_to_2dp()
の定義はどのようにすればよいでしょうか?
http://php.net/manual/en/function.round.php
e.g.
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06