Hi,
public class math
{
public static void main(
String a[])
{
System.out.println(Math.round(-2.5));// o/p is -2....line 1
System.out.println(Math.round(-2.4));// o/p is -2....line 2
System.out.println(Math.round(-2.6));// o/p is -3....line 3
System.out.println(Math.round(2.5)); // o/p is 3...as expected.
System.out.println(Math.round(2.4)); // o/p is 2...as expected.
System.out.println(Math.round(2.6)); // o/p is 3...as expected.
}
}
round returns a long for double, returns an int for float. (closest int or long value to the argument)
The result is rounded to an integer by adding � , taking the floor of the result, and casting the result to type int / long.
NOw...look at the o/p of line 1 and line 3 (-2.5 is giving -2 whereas line -2.6 is giving -3.) . As fer as in +ve no. this is not the rule. In positive nos. both 2.5 and 2.6 will give 3.Now look at line 2 also.
same problem here.
Can any1 tell me what is real rule for -ve no's roundness..
I am simply not geting any rule??
Thanks In Advance.
<marquee>
Ratul Banerjee </marquee>