For rounding, use the Math.round() method. It only rounds to a whole number, so multiply by 100d and round and divide by 100d. To print out 12.3400 use the methods which use % tags, eg printf or format. Details in the Formatter class.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 46393

51

posted

0

By the way, you are not using the same rounding convention as in Math.round(). For round-toward-zero, multiply by 100, cast to an int or long and divide by 100d.