3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function format_number($number) { $str = number_format($number, 4, '.', ''); $str = preg_replace('/(?<=\d{2})0+$/', '', $str); return $str; } var_dump(format_number(4.0)); var_dump(format_number(4.5)); var_dump(format_number(4.454)); var_dump(format_number(4.54545454)); var_dump(format_number(4.450));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(4) "4.00" string(4) "4.50" string(5) "4.454" string(6) "4.5455" string(4) "4.45"