3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $numbers = array( 1234, 1234.05, 1234.005, 1234.5, 1234.55, 1234.505, 1234.555, 3, 3.05, 3.5, 3.55, 3.555, 3.5555, 5.49, 5.255, 5.252, 5.249, 5.244, 2.245, ); function format_to_komma_ruggit($number, $decimals) { $number = round($number, $decimals); $number = number_format($number, strlen(substr(strrchr($number, "."), 1)), ',', '.'); return $number; } foreach ($numbers as $number) { echo $number . ' => ' . format_to_komma_ruggit($number, 1); echo "\r\n"; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
1234 => 1.234 1234.05 => 1.234,1 1234.005 => 1.234 1234.5 => 1.234,5 1234.55 => 1.234,6 1234.505 => 1.234,5 1234.555 => 1.234,6 3 => 3 3.05 => 3,1 3.5 => 3,5 3.55 => 3,6 3.555 => 3,6 3.5555 => 3,6 5.49 => 5,5 5.255 => 5,3 5.252 => 5,3 5.249 => 5,2 5.244 => 5,2 2.245 => 2,2