⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numberformatter.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.i18n;

import java.text.NumberFormat;
import java.util.Locale;

/** Class to demonstrate the use of the NumberFormat
  * class for currency and other numbers
  */
public class NumberFormatter {
   /** Test program for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      double x = 100000000.12345;
      NumberFormat nfDefault
         = NumberFormat.getInstance();
      NumberFormat nfGermany
         = NumberFormat.getInstance( Locale.GERMANY );
      test( "Default number format",
            nfDefault, nfGermany, x );
      nfDefault.setMaximumFractionDigits( 6 );
      nfGermany.setMaximumFractionDigits( 6 );
      test( "Default number format, more precision",
            nfDefault, nfGermany, x );
      double y = 0.12345;
      NumberFormat nfDefaultPc
         = NumberFormat.getPercentInstance();
      NumberFormat nfGermanyPc
         = NumberFormat.getPercentInstance(
                                     Locale.GERMANY );
      test( "Percent format",
            nfDefaultPc, nfGermanyPc, y );
      double z = 12345.6789;
      NumberFormat nfDefaultCr
         = NumberFormat.getCurrencyInstance();
      NumberFormat nfGermanyCr
         = NumberFormat.getCurrencyInstance(
                                     Locale.GERMANY );
      test( "Currency format",
            nfDefaultCr, nfGermanyCr, z );
   }
   /** Test method
     * @param label the name of the test
     * @param defNf the NumberFormat object for the
     *    default locale
     * @param gerNf the NumberFormat object for the
     *    GERMANY locale
     * @param value the value to be formatted.
     */
   public static void test( String label,
                            NumberFormat defNf,
                            NumberFormat gerNf,
                            double value ) {
      System.out.println( label );
      System.out.println( "\tdefault locale: "
                          + defNf.format( value ) );
      System.out.println( "\tGerman locale:  "
                          + gerNf.format( value ) );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -