sgrgmngt
sgrgmngt

Reputation: 917

Round off in JAVA

I want to round off a value for ex:

12.166666 ----> 12.00

12.49999 ----> 12.00

12.5111 ----> 13.00

12.9999 ----> 13.00

I want to to round off wrt 50 paise.

Upvotes: 0

Views: 14029

Answers (2)

Ruan Mendes
Ruan Mendes

Reputation: 92274

You can use Math.round . For documentation take a look at: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(double)

Upvotes: 0

npinti
npinti

Reputation: 52185

You can take a look at the Math.round(double a) method.

System.out.println(Math.round(12.51));//Yields 13
System.out.println(Math.round(12.49));//Yields 12
System.out.println(Math.round(12.50));//Yields 13

Upvotes: 9

Related Questions