• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Reg. rint()

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does the rint() method work ?
As per the API


public static double rint(double a)
Returns the double value that is closest in value to a and is equal to a mathematical integer. If two double values that are mathematical integers are equally close to the value of the argument


 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
copy pasted what is written in the API. whats confusing you (please point out)?


public static double rint(double a)
Returns the double value that is closest in value to a and is equal to a mathematical integer. If two double values that are mathematical integers are equally close to the value of the argument, the result is the integer value that is even. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Parameters:
a - a double value.
Returns:
the closest double value to a that is equal to a mathematical integer.

 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain it with reference to an example.
thanks
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which class in the API does this method belong to?

Originally posted by Amit Agrawal*:
copy pasted what is written in the API. whats confusing you (please point out)?


public static double rint(double a)
Returns the double value that is closest in value to a and is equal to a mathematical integer. If two double values that are mathematical integers are equally close to the value of the argument, the result is the integer value that is even. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Parameters:
a - a double value.
Returns:
the closest double value to a that is equal to a mathematical integer.


 
Amit Agrawal
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an example for the same, Please lemme know if it is still not clear.


Originally posted by Angela Narain:
Can someone explain it with reference to an example.
thanks


Originally posted by Roopa Bagur
Which class in the API does this method belong to?


As you might have guessed, it belongs to Math class.
[This message has been edited by Amit Agrawal* (edited September 18, 2001).]
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this mean that if you pass 6.5 rint() will return 6 instead of 7 since 6 is even ?

Originally posted by Amit Agrawal*:
[B]Here is an example for the same, Please lemme know if it is still not clear.


Originally posted by Roopa Bagur
Which class in the API does this method belong to?


As you might have guessed, it belongs to Math class.
[This message has been edited by Amit Agrawal* (edited September 18, 2001).][/B]


 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Amit for the explanation. Its very clear to me now..
Yes Roopa, the result of Math.rint(6.5) will be 6.0
as both 6.0 and 7.0 are equally close but as 6.0 is even
so it is taken.
 
reply
    Bookmark Topic Watch Topic
  • New Topic