0
double1 = .05100000000003;

double2 = .05295;

How do I round a decimal to three places? Respectively, I'd like the output to do this 0.051 and 0.053.

I tried Math.round(double1); but I got back 0.0.

Any ideas would be greatly appreciated thanks.

1 Answers1

1

Try the following code in Java. The number of zeros indicates how many decimal places you would like to round to. (In this case there are 3 zeros).

(double)Math.round(value * 1000d) / 1000d

EDIT: same answer is provided in this previous StackOverflow Post