I like to use this since it's so similar to printf()
double doubleValue = 123.4567895;
String.format("%.2f", doubleValue); // returns "123.46"
Edit: This does not truncate, but rounds half-up.
More info on how to use the String.format()
, and java.util.Formatter
:
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html