A simple trick is to generate a shorter version of your variable by multiplying it with e.g. 100
, rounding it and dividing it by 100.0
again. This way you generate a variable, with 2 decimal places:
double new_variable = Math.round(old_variable*100) / 100.0;
This "cheap trick" was always good enough for me, and works in any language (I am not a Java person, just learning it).