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) . "
";
echo " " . round(11.505, 2) . "
";
echo " " . round(111.505, 2) . "
";
echo " " . round(1111.505, 2) . "
";
echo " " . round(11111.505, 2) . "
";
echo " " . round(111111.505, 2) . "
";
echo " " . round(1111111.505, 2) . "
";
echo " " . round(11111111.505, 2) . "
";
echo "" . round(111111111.505, 2) . "
";
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't update PHP, since it's shared server.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…