Java by API/java.text/DecimalFormatSymbols

Материал из Java эксперт
Перейти к: навигация, поиск

DecimalFormatSymbols: setCurrencySymbol(String currency)

   <source lang="java">

import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; public class MainClass {

 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#,###.##");
   }
   System.out.println(nf.format(1234.56));
 }

}

      </source>
   
  
 
  



DecimalFormatSymbols: setZeroDigit(char zeroDigit)

   <source lang="java">

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 MainClass extends JPanel {

 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);
   }
   JLabel label = new JLabel(nf.format(1234567.89));
   label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
   add(label);
 }
 public static void main(String[] argv) {
   MainClass panel = new MainClass();
   JFrame frame = new JFrame("Arabic Digits");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.getContentPane().add("Center", panel);
   frame.pack();
   frame.setVisible(true);
 }

}

      </source>