List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:MainClass.java
public static void main(String args[]) throws Exception { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setParseIntegerOnly(false); double usersNumber = 1976.0826; numberFormat = NumberFormat.getNumberInstance(); System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber)); }
From source file:Main.java
public static void main(String[] argv) { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setParseIntegerOnly(false); double usersNumber = 197912.29; numberFormat = NumberFormat.getNumberInstance(Locale.US); System.out.println("User's number (US): " + numberFormat.format(usersNumber)); numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY); System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber)); numberFormat = NumberFormat.getNumberInstance(); System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber)); }
From source file:NumberFormatRounding.java
public static void main(String[] args) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);// www .j av a2 s .c om nf.setRoundingMode(RoundingMode.FLOOR); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); }
From source file:NumberFormatRounding.java
public static void main(String[] args) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);/*from w ww. j a v a 2 s .c om*/ nf.setRoundingMode(RoundingMode.CEILING); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); }
From source file:NumberFormatRounding.java
public static void main(String[] args) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);/*from w w w. ja va2 s. c om*/ nf.setRoundingMode(RoundingMode.HALF_DOWN); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setParseIntegerOnly(false); double usersNumber = 1976.0826; numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY); System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber)); }
From source file:NumberFormatRounding.java
public static void main(String[] args) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);/* w w w.ja v a 2 s . c o m*/ nf.setRoundingMode(RoundingMode.HALF_DOWN); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); nf.setRoundingMode(RoundingMode.FLOOR); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); nf.setMaximumFractionDigits(2); nf.setRoundingMode(RoundingMode.CEILING); System.out.println("Default rounding mode: " + nf.getRoundingMode()); System.out.println("123.454 rounds to " + nf.format(123.454)); System.out.println("123.455 rounds to " + nf.format(123.455)); System.out.println("123.456 rounds to " + nf.format(123.456)); System.out.println(); }
From source file:NumFormat2.java
/** The main (and only) method in this class. */ public static void main(String[] av) { // Get a format instance NumberFormat form = NumberFormat.getInstance(); // Set it to look like 999.99[99] form.setMinimumIntegerDigits(3);/*from www . j av a2s . c o m*/ form.setMinimumFractionDigits(2); form.setMaximumFractionDigits(4); // Now print using it. for (int i = 0; i < data.length; i++) System.out.println(data[i] + "\tformats as " + form.format(data[i])); }
From source file:MainClass.java
public static void main(String[] av) { double data[] = { 0, 1, 22d / 7, 100.2345678 }; NumberFormat form = NumberFormat.getInstance(); // Set it to look like 999.99[99] form.setMinimumIntegerDigits(3);/*from w w w . ja v a2 s. c om*/ form.setMinimumFractionDigits(2); form.setMaximumFractionDigits(4); // Now print using it. for (int i = 0; i < data.length; i++) System.out.println(data[i] + "\tformats as " + form.format(data[i])); }
From source file:MainClass.java
public static void main(String[] argv) { NumberFormat nf = NumberFormat.getInstance(); if (nf instanceof DecimalFormat) { DecimalFormat df = (DecimalFormat) nf; DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setCurrencySymbol("AD$"); df.setDecimalFormatSymbols(dfs); df.applyPattern("\u00a4#,###.##"); }//from w ww.ja v a 2 s. c om System.out.println(nf.format(1234.56)); }