-5

I need the rounding logic in the following pattern..for 2.23 it should be 2.2 ,for 2.26 it should be 2.3... Please Help out

2 Answers2

1
double a = <ur NUmber>;
double roundOff = (double) Math.round(a*10)/10;

Hope this would help you. here 2.25 would be round off to 2.3

raki
  • 195
  • 1
  • 10
0

If you want to print, than use printf method, It has default rounding.

System.out.printf("%.1f", 2.23);
System.out.printf("%.1f", 2.26);

If you need rounding value for calculation than use Math.round

double newValue= (double)Math.round(value*10)/10;
Masudul
  • 21,823
  • 5
  • 43
  • 58