Java examples for java.lang:double Format
Use comma Separator to format a number
//package com.java2s; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Main { public static void main(String[] argv) { String number = "31231"; System.out.println(commaSeparator(number)); }// w w w . jav a2 s. c o m public static String commaSeparator(String number) { Double d = Double.parseDouble(number); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setGroupingSeparator('-'); DecimalFormat formatter = new DecimalFormat("###,###", symbols); String str = formatter.format(d); return str; } }