How can I truncate a double to only two decimal places in Java? [duplicate]
This question already has an answer here: How to round a number to n decimal places in Java 29 answers For example I have the variable 3.545555555, which I would want to truncate to just 3.54. Bozho If you want that for display purposes, use java.text.DecimalFormat : new DecimalFormat("#.##").format(dblVar); If you need it for calculations, use java.lang.Math : Math.floor(value * 100) / 100; Cedric Dubourg DecimalFormat df = new DecimalFormat(fmt); df.setRoundingMode(RoundingMode.DOWN); s = df.format(d); Check available RoundingMode and DecimalFormat . Mani Bit Old Forum, None of the above