File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Clarify... Math Functions.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Clarify... Math Functions...." Watch "Clarify... Math Functions...." New topic

Clarify... Math Functions....

Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
How does the Math.round() function work for negative numbers... Explain with examples...

Pinkal Patel
Ranch Hand

Joined: Jun 16, 2006
Posts: 57
Will work same as abs number ...

Only diffrance is
Upto .5 it will tack lower range
and than onverds it will tack upper limit

Pinkal Patel<br />SCJP 1.5<br />Preparing for SCWCD
Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
Give example....
Pramila Chinguru
Ranch Hand

Joined: May 05, 2006
Posts: 54
Math.round is calculated as below
1. add 0.5 to the number
2. then,take the floor of it.

Eg 1: 2.4

1. 2.9
2. Floor(2.9) = 2 (not 2.0, since round returns either long or int).

Eg 2: -2.4

1. -1.9
2. floor(-1.9) = -2

point of note: floor of negative number is equivalent to ciel of its positive number.
krish bajaj
Ranch Hand

Joined: Jun 19, 2006
Posts: 31
hello there

yes shaiber pramila is exactly write
I agree. Here's the link:
subject: Clarify... Math Functions....
It's not a secret anymore!