Arabic Digits : DecimalFormat « I18N « Java Tutorial






Arabic Digits
import java.awt.Font;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ArabicDigitsI18N extends JPanel {
  public ArabicDigitsI18N() {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setZeroDigit('\u0660');
    df.setDecimalFormatSymbols(dfs);

    JLabel label = new JLabel(df.format(1234567.89));

    label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    add(label);
  }

  public static void main(String[] argv) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", new ArabicDigitsI18N());
    frame.pack();
    frame.setVisible(true);
  }
}








13.13.DecimalFormat
13.13.1.new DecimalFormat('0.00')
13.13.2.new DecimalFormat('#.#') two digits
13.13.3.new DecimalFormat('#.######') more digits
13.13.4.new DecimalFormat('.######'), keep fraction
13.13.5.new DecimalFormat('#.000000'), append zero
13.13.6.new DecimalFormat('#,###,###'), group
13.13.7.Arabic DigitsArabic Digits
13.13.8.Format a number with leading zeros
13.13.9.The . symbol indicates the decimal point
13.13.10.The , symbol is used to group numbers
13.13.11.The ; symbol is used to specify an alternate pattern for negative values
13.13.12.The ' symbol is used to quote literal symbols
13.13.13.Use group separators and show trailing zeros
13.13.14.Display numbers in scientific notation
13.13.15.Displaying numbers with commas
13.13.16.new DecimalFormat('##00')
13.13.17.The 0 symbol shows a digit or 0 if no digit present