List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:Main.java
public Main() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);//from w w w. j av a 2s .com JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:MainClass.java
public MainClass() { NumberFormat nf = NumberFormat.getInstance(); if (nf instanceof DecimalFormat) { DecimalFormat df = (DecimalFormat) nf; DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); // set the beginning of the range to Arabic digits dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs); }/* w ww . j ava 2 s. com*/ JLabel label = new JLabel(nf.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:Main.java
public static String getBalanceDisplay(long amount, int floatSize) { NumberFormat format = NumberFormat.getInstance(); if (NumEmpty == amount) return ""; if (floatSize < 0) { // error input return Long.toString(amount); }// www . java 2 s.c om if (floatSize == 2) { boolean zs = true; if (amount < 0) { zs = false; amount = -amount; } long m = amount / 100; long f = amount - m * 100; return (zs ? "" : "-") + format.format(m) + "." + (f > 9 ? Long.toString(f) : "0" + f); } else if (floatSize == 0) { return format.format(amount); } else { // error input return format.format(amount); } }
From source file:ArabicDigitsI18N.java
public ArabicDigitsI18N() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);//from w w w . ja v a2 s . c o m JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:com.norbl.util.StringUtil.java
public static String f2(double x) { NumberFormat f = NumberFormat.getInstance(); f.setMaximumFractionDigits(2);//from w ww .j av a2s. c om f.setMinimumFractionDigits(2); return (f.format(x)); }
From source file:funcoes.funcoes.java
public static String paraFormatoDinheiro(Double valor) { NumberFormat formato2 = NumberFormat.getInstance(); //JOptionPane.showMessageDialog(null, valor); //JOptionPane.showMessageDialog(null, formato2); return formato2.format(valor); }
From source file:ChoiceFormatDemo.java
static void displayMessages(Locale currentLocale) { System.out.println("currentLocale = " + currentLocale.toString()); System.out.println();/* w w w . j ava 2 s . c o m*/ ResourceBundle bundle = ResourceBundle.getBundle("ChoiceBundle", currentLocale); MessageFormat messageForm = new MessageFormat(""); messageForm.setLocale(currentLocale); double[] fileLimits = { 0, 1, 2 }; String[] fileStrings = { bundle.getString("noFiles"), bundle.getString("oneFile"), bundle.getString("multipleFiles") }; ChoiceFormat choiceForm = new ChoiceFormat(fileLimits, fileStrings); String pattern = bundle.getString("pattern"); Format[] formats = { choiceForm, null, NumberFormat.getInstance() }; messageForm.applyPattern(pattern); messageForm.setFormats(formats); Object[] messageArguments = { null, "XDisk", null }; for (int numFiles = 0; numFiles < 4; numFiles++) { messageArguments[0] = new Integer(numFiles); messageArguments[2] = new Integer(numFiles); String result = messageForm.format(messageArguments); System.out.println(result); } }
From source file:ch.citux.td.util.FormatUtils.java
public static String formatNumber(long number) { return NumberFormat.getInstance().format(number); }
From source file:com.discursive.jccook.lang.StopWatchExample.java
private void start() { NumberFormat format = NumberFormat.getInstance(); System.out.println("How long does it take to take the sin of 0.34 ten million times?"); clock.start();//w w w. j av a 2 s .com for (int i = 0; i < 100000000; i++) { Math.sin(0.34); } clock.stop(); System.out.println("It takes " + clock.getTime() + " milliseconds"); System.out.println("How long does it take to multiply 2 doubles one billion times?"); clock.reset(); clock.start(); for (int i = 0; i < 1000000000; i++) { double result = 3423.2234 * 23e-4; } clock.stop(); System.out.println("It takes " + clock.getTime() + " milliseconds."); System.out.println("How long does it take to add 2 ints one billion times?"); clock.reset(); clock.start(); for (int i = 0; i < 1000000000; i++) { int result = 293842923 + 33382922; } clock.stop(); System.out.println("It takes " + clock.getTime() + " milliseconds."); System.out.println("Testing the split() method."); clock.reset(); clock.start(); try { Thread.sleep(1000); } catch (Exception e) { } clock.split(); System.out.println("Split Time after 1 sec: " + clock.getTime()); try { Thread.sleep(1000); } catch (Exception e) { } System.out.println("Split Time after 2 sec: " + clock.getTime()); clock.unsplit(); try { Thread.sleep(1000); } catch (Exception e) { } System.out.println("Time after 3 sec: " + clock.getTime()); }
From source file:org.sakaiproject.evaluation.tool.reporting.LikertPercentageItemLabelGenerator.java
public LikertPercentageItemLabelGenerator(int totalItems) { super("", NumberFormat.getInstance()); this.totalItems = totalItems; this.doubleTotalItems = totalItems; }