A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Clarify... Math Functions....
Shiaber Shaam
Ranch Hand
Joined: Jun 16, 2006
Posts: 252
posted
Jun 21, 2006 22:19:00
0
How does the Math.round() function work for negative numbers... Explain with examples...
$Hi/\bEr
Pinkal Patel
Ranch Hand
Joined: Jun 16, 2006
Posts: 57
posted
Jun 21, 2006 22:53:00
0
Math.round()
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
posted
Jun 21, 2006 23:07:00
0
Give example....
Pramila Chinguru
Ranch Hand
Joined: May 05, 2006
Posts: 54
posted
Jun 22, 2006 00:20:00
0
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
posted
Jun 22, 2006 00:38:00
0
hello there
yes shaiber pramila is exactly write
I agree. Here's the link:
http://aspose.com/file-tools
subject: Clarify... Math Functions....
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter