This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.round() for negative numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.round() for negative numbers" Watch "Math.round() for negative numbers" New topic
Author

Math.round() for negative numbers

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Can someone please explain how Math.round() works for negative numbers.
anandkumar gangoni
Greenhorn

Joined: May 30, 2004
Posts: 16
well... Math.round method comes in 2 flavours where one form returns int on taking float as an argument and the other return long on taking double as argument.

whether the argument is negative or positive wat it does is........ it adds 0.5 to the argument and returns the floor value in int or long type depending on the argument provied.

shall be waiting to here from you.
till then this is Anand saying....
Cheers!!
anandkumar gangoni
Greenhorn

Joined: May 30, 2004
Posts: 16
an addition to wat i said

If NaN is the argument passed to Math.round, then the return value is zero.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If you're wondering how anandkumar gangoni could possibly know such a thing, I'll give you a hint to his wisdom. Take a look at the J2SE API documentation.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.round() for negative numbers