• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between "rint" and "round" methods in Math class?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Math class API states
-public static double rint(double d)
this method returns a double value that is closest in value to the argument and is equal to a mathematical integer.
-public static long (or int) round(double d)
this method returns closest long (or int) to the argument.
Could any one tell me what exactly the difference between these two methods apart from their return types?
Thankyou
Mallik HM
[ November 02, 2002: Message edited by: Mallik HM ]
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be sure to read the long descriptions, not just the short ones. The functions produce different results when the argument is exactly halfway between two integers. round() rounds up, but rint() rounds to an even integer.

% java RoundTest 3.5
round(3.5) = 4
rint(3.5) = 4.0
% java RoundTest 4.5
round(4.5) = 5
rint(4.5) = 4.0
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron ,
Thank you very much.
Mallik
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy all -- just wanted to point out that the exam objectives require *only* the following methods:
abs, ceil, floor, max, min, random, round, sin, cos, tan, sqrt, toDegrees, toRadians
And that's it!
Don't know about you, but I'm much too lazy to study more than I need to , so for all of you who're overwhelmed as it is, the list above is all that's required of the Math class in the exam.
Cheers,
Kathy
of course, feel free to study more
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic