This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

239 points
Picture
Submitted by
Billy Wood
over 4 years ago

Math Functions 1 - output of "round(x.xx0xxx)"

Not a question, but a comment:

<p>
<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen
$round_decimal = round(1.2304987026, 3);
echo $round_decimal;
?>
</p>

I just noticed that the above gives an output of 1.23 (ie the third decimal place is ignored, rightly, because it is zero). This confused me for a while!

I also felt it unfair that my answer didn't pass, at first, but I would not have learned this little extra lesson otherwise!


1 vote

permalink

thanks for the info! Interesting.

274 points
6869c54dfa694e2063f3381b534e64dd?s=140&d=retro
Submitted by
collinferg
about 4 years ago