rounding - PHP round different results -


this question has answer here:

hi got problem rounding. ex.:

$x = 100; $y = 4.2030;  $result = round($x / $y, 2);  

$result 23.79

but

  $result2 = round(23.79 * 4.2030, 2); 

$result2 99.99 , it's incorrect. should 100 ($result2 equal $x)

how slove ?

your round precision 2 decimal places. if trying whole numbers need omit precision argument:

$result2 = round(23.79 * 4.2030); 

note: lower precision argument, more inaccurate result actual results.

you can use ceil() , floor() if looking round in specific direction (ceil() round up, floor() round down).


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -