Java-i18n-set-minmax

提供:Dev Guides
2020年6月22日 (月) 20:01時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

Java内部化-最小/最大精度の設定

この例では、整数と小数部分の両方に最小桁と最大桁を設定しています。

IOTester.java

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

public class I18NTester {
   public static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");

      NumberFormat numberFormat = NumberFormat.getInstance(enLocale);
      numberFormat.setMinimumIntegerDigits(2);
      numberFormat.setMaximumIntegerDigits(3);

      numberFormat.setMinimumFractionDigits(2);
      numberFormat.setMaximumFractionDigits(3);

      System.out.println(numberFormat.format(12234.763443));
   }
}

出力

次の結果が出力されます。

234.763

link:/cgi-bin/printpage.cgi [__印刷]