3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $numbers = array( 1234, 1234.0, 1234.05, 1234.005, 1234.5, 1234.50, 1234.55, 1234.505, 1234.555, 1234.5000, 1234.5500, 1234.5550, 1234.5555, 3, 3.0, 3.05, 3.5, 3.50, 3.55, 3.550, 3.555, 3.5550, 3.5555, 5.49, 5.255, 5.249, 5.244, 2.245, ); function format_to_komma_ruggit($number) { $number = round($number); $number = number_format($number, strlen(substr(strrchr($number, "."), 1)), ',', '.'); return $number; } foreach ($numbers as $number) { echo (float)$number . ' => ' . format_to_komma_ruggit($number); echo PHP_EOL; }
Output for 4.3.10 - 4.4.9, 5.0.2 - 7.1.0
1234 => 1.234 1234 => 1.234 1234.05 => 1.234 1234.005 => 1.234 1234.5 => 1.235 1234.5 => 1.235 1234.55 => 1.235 1234.505 => 1.235 1234.555 => 1.235 1234.5 => 1.235 1234.55 => 1.235 1234.555 => 1.235 1234.5555 => 1.235 3 => 3 3 => 3 3.05 => 3 3.5 => 4 3.5 => 4 3.55 => 4 3.55 => 4 3.555 => 4 3.555 => 4 3.5555 => 4 5.49 => 5 5.255 => 5 5.249 => 5 5.244 => 5 2.245 => 2
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
1234 => 1.234 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234 => 1.234 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.05 => 1.234 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.005 => 1.234 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.5 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.5 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.55 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.505 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.555 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.5 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.55 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.555 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL1234.5555 => 1.235 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3 => 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3 => 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.05 => 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.5 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.5 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.55 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.55 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.555 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.555 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL3.5555 => 4 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL5.49 => 5 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL5.255 => 5 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL5.249 => 5 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL5.244 => 5 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL2.245 => 2 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mDjWB on line 44 PHP_EOL