# Math.round()

Varsha Dighe

Ranch Hand

Posts: 32

P SOLAIAPPAN

Ranch Hand

Posts: 68

posted 15 years ago

Math.round() will always roun up to nearest high value.

For e.g

Math.round(9.4)=9 // any value <9.5 will be rounded to 9<br /> Math.round(9.5)=10 // any value >=9.5 will be rounded to 10

Math.round(9.6)=10 //

Math.round(-9.5)= -9 // Note here -9.5 > -9.6 hence all the

numbers which are >=-9.5 will be

rounded to -9 which is a bigger number

than -10.

Math.round(-9.4)= -9 // -9.4>-9.5 hence -9

Math.round(-9.6)=-10 // since -9.6<-9.5<br /> Remember that -9 >-10

I hope u r clear

solaiappan

- 0

Math.round() will always roun up to nearest high value.

For e.g

Math.round(9.4)=9 // any value <9.5 will be rounded to 9<br /> Math.round(9.5)=10 // any value >=9.5 will be rounded to 10

Math.round(9.6)=10 //

Math.round(-9.5)= -9 // Note here -9.5 > -9.6 hence all the

numbers which are >=-9.5 will be

rounded to -9 which is a bigger number

than -10.

Math.round(-9.4)= -9 // -9.4>-9.5 hence -9

Math.round(-9.6)=-10 // since -9.6<-9.5<br /> Remember that -9 >-10

I hope u r clear

solaiappan

kamesh vadarevu

Greenhorn

Posts: 20

kamesh vadarevu

Greenhorn

Posts: 20

Udayan Naik

Ranch Hand

Posts: 135

posted 15 years ago

- 0

Hi Varsha.The general rule about rounding is :

round() will give the closest result to the argument passed to it. So from 0.0 to 0.4 it will give 0.0(nearest lower number) and from 0.5 to 1.0 it will give 1.0(nearest higher number).When u give a middle range argument(like 0.5) it will give the next higher number(like 1.0).

For negative numbers , -9 is greater than -9.5 thus u get round(-9.5) as -9 which is nearest higher number.

For -9.6 the nearest lower number is -10.0 thus round(-9.6) is -10.

------------------

Come on in !! Drinks are on the house in the Big Moose Saloon !!

round() will give the closest result to the argument passed to it. So from 0.0 to 0.4 it will give 0.0(nearest lower number) and from 0.5 to 1.0 it will give 1.0(nearest higher number).When u give a middle range argument(like 0.5) it will give the next higher number(like 1.0).

For negative numbers , -9 is greater than -9.5 thus u get round(-9.5) as -9 which is nearest higher number.

For -9.6 the nearest lower number is -10.0 thus round(-9.6) is -10.

------------------

Come on in !! Drinks are on the house in the Big Moose Saloon !!

Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform

I agree. Here's the link: http://aspose.com/file-tools |