first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Java Diddler: An Example of String Formatting; MRJ SDK 2.1

//The number we want to show. double dbl = 10000.0 / 3.0;

//Get a Locale object from the java.util package. java.util.Locale locale = java.util.Locale.getDefault();

//Format the number for a given Locale. java.text.NumberFormat nf = java.text.NumberFormat.getNumberInstance(locale.US); java.lang.String strUSnum = nf.format(dbl);

//Format the number as Locale currency. java.text.NumberFormat cf = java.text.NumberFormat.getCurrencyInstance(locale.US); java.lang.String strUSD = cf.format(dbl);

//Format the number with a custom format. java.text.DecimalFormat df = new java.text.DecimalFormat(",##0.000000 foobars"); java.lang.String strCustomNum = df.format(dbl);

java.lang.System.out.println(strUSnum); java.lang.System.out.println(strUSD); java.lang.System.out.println(strCustomNum);

mod date: 2000-09-16T14:28:00.000Z