Java tutorial
import java.text.NumberFormat; public class Main { public static void main(String args[]) { NumberFormat nf = NumberFormat.getInstance(); System.out.println("Default format: " + nf.format(1234567.678)); nf.setMaximumFractionDigits(2); System.out.println("Format with two decimal places: " + nf.format(1234567.678)); } } /* Default format: 1,234,567.678 Format with two decimal places: 1,234,567.68 */