rounding-error

PHP rounding error

只谈情不闲聊 提交于 2019-11-27 15:08:01
I'm using PHP 5.2.13 on my linux server. I'm getting weird error when rounding numbers. This is my test case: <?php echo " " . round(1.505, 2) . "\n"; echo " " . round(11.505, 2) . "\n"; echo " " . round(111.505, 2) . "\n"; echo " " . round(1111.505, 2) . "\n"; echo " " . round(11111.505, 2) . "\n"; echo " " . round(111111.505, 2) . "\n"; echo " " . round(1111111.505, 2) . "\n"; echo " " . round(11111111.505, 2) . "\n"; echo "" . round(111111111.505, 2) . "\n"; This is results: 1.51 11.51 111.51 1111.51 11111.51 111111.51 1111111.5 11111111.51 111111111.51 Anyone knows what causes this? I can

PHP rounding error

纵然是瞬间 提交于 2019-11-26 18:28:51
问题 I'm using PHP 5.2.13 on my linux server. I'm getting weird error when rounding numbers. This is my test case: <?php echo " " . round(1.505, 2) . "\n"; echo " " . round(11.505, 2) . "\n"; echo " " . round(111.505, 2) . "\n"; echo " " . round(1111.505, 2) . "\n"; echo " " . round(11111.505, 2) . "\n"; echo " " . round(111111.505, 2) . "\n"; echo " " . round(1111111.505, 2) . "\n"; echo " " . round(11111111.505, 2) . "\n"; echo "" . round(111111111.505, 2) . "\n"; This is results: 1.51 11.51 111