rounding - PHP round function returned a weird result -


i execute simple script round(8.32, 1) in cgi, returns 8.300000000000001. when execute in cli php -r "echo round(8.32, 1);", result 8.3 expected. php version 5.6.2.

you have different settings of precision in config.

ini_set('precision', 10); var_dump(round(8.32, 1)); // double(8.3)  ini_set('precision', 20); var_dump(round(8.32, 1)); // double(8.3000000000000007105) 

why happens read here: http://en.wikipedia.org/wiki/ieee_floating_point


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -