-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,832
  • 23
  • 70
  • 127
user1346316
  • 264
  • 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,669
  • 12
  • 55
  • 103
Saurabh Ande
  • 427
  • 3
  • 13