rounding - PHP Round unexpected result -


i have problem php round function. rounds function not working correctly:

$value = 562.92578125;  round($value,1); // return 562.9 (correctly) round($value,2); // return 562.9299999999999 (wrong) round($value,3); // return 562.926 (correctly) 

as workaround try use:

number_format(round($value, 1), 1); number_format(round($value, 2), 2); number_format(round($value, 3), 3); 

also, have here: can rely on php php.ini precision workaround floating point issue


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -