I use double values in my project and I would like to always show the first two decimal digits, even if them are zeros. I use this function for rounding and if the value I print
Use the java.text.NumberFormat for this:
java.text.NumberFormat
NumberFormat nf= NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); nf.setRoundingMode(RoundingMode.HALF_UP); System.out.print(nf.format(decimalNumber));