Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Clarify... Math Functions....

Shiaber Shaam
Ranch Hand
Posts: 252
How does the Math.round() function work for negative numbers... Explain with examples...

Pinkal Patel
Ranch Hand
Posts: 57
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

Shiaber Shaam
Ranch Hand
Posts: 252
Give example....

Pramila Chinguru
Ranch Hand
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
Posts: 31
hello there

yes shaiber pramila is exactly write