-2

Question 1:

Assume Double d = 10.233444. I want to convert and put result into same double, so that my value should be d= 10.23;

Question 2:

Assume Double d = 10.235444. I want to convert and put result into same double, so that my value should be d= 10.24;

How to do this in java?

sdoca
  • 7,622
  • 23
  • 66
  • 124
user1346316
  • 254
  • 1
  • 3
  • 10

1 Answers1

0

If you want to roundoff value

Double d = 10.233444;

double roundOff = Math.round(d * 100.0) / 100.0;
System.out.println(roundOff);
// Output is 10.24

Double d2 = 10.235444;

roundOff = Math.round(d2 * 100.0) / 100.0;
System.out.println(roundOff);
// Output is 10.25
Afzaal Ahmad Zeeshan
  • 15,234
  • 11
  • 53
  • 100
Saurabh Ande
  • 417
  • 3
  • 12