round to two decimal places

is there an easy way to round a double to two decimal places?

i.e. 1.98999 would round to 1.99

the math.round method only rounds to nearest integer.

decimalformat class converts number to a string.

i figure there must be an easy way to do this...?? pls advise.

Re: round to two decimal places

Simple solution:

(Math.round(d*100))/100

Re: round to two decimal places

Quote:

Originally Posted by

**HansW** Simple solution:

Wrong. Not a solution at all.

What Every Computer Scientist Should Know About Floating-Point Arithmetic

And since this thread is over 4 years old, I'm closing it. If you have any questions, please start your own thread.

db