programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# Math.Round

Ranch Hand
Posts: 97
• Number of slices to send:
Optional 'thank-you' note:
Math.Round - the result is calculated by addig 0.5 to the argument and then take Math.floor of the result

Does this apply to negative value too ?

Ranch Hand
Posts: 1090
• Number of slices to send:
Optional 'thank-you' note:
Hi Robbie
Yes this applies to all and the Math.round() method starts with a small r.
Did that help.

Robbie kyodo
Ranch Hand
Posts: 97
• Number of slices to send:
Optional 'thank-you' note:
so if Math.round (-3.4);
is -3.4 +0.5 = -2.9
then take floor()
= -3
ok confirm. thanks

Anupam Sinha
Ranch Hand
Posts: 1090
• Number of slices to send:
Optional 'thank-you' note:
Yes. You are correct.

Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
"Math.Round - the result is calculated by addig 0.5 to the argument and then take Math.floor of the result"
Robbie, I know you know this, but for the sake of completeness, don't forget the cast to long or int after applying Math.floor. (Or put another way, don't forget that Math.floor returns a double which must then be cast.)

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?