You can use the java.text.DecimalFormat
class to format decimal numbers. e.g.
Code:
public static void main(String[] args) {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat formatter = new DecimalFormat("#.00", symbols);
System.out.println(formatter.format(BigDecimal.valueOf(12.456)));
System.out.println(formatter.format(BigDecimal.valueOf(12L)));
}
Output:
12.46
12.00
See more in Customizing Formats (The Java Tutorials > Internationalization > Formatting).