Monday, November 06, 2006

 

How these operators, /, div, round, are different

It's important to be very clear in your mind about the differences among these three operators.

15/4 = 3.75
15 div 4 = 3
round (15/4) = 4


/ is normal division. When speaking we say "15 divided by 4."

div is special. It gives the result of division and throws away any remainder, even if the remainder is as large as .9. It is not the same as round(). When speaking we say "15 div 4."

round() rounds a number, either up or down, according to the usual rules of math, that is, rounding up if >= .5 and rounding down if < .5.



<< Home

This page is powered by Blogger. Isn't yours?