English 中文(简体)
JAVA I18N - Set Min/Max Precision
  • 时间:2024-12-22

Java Internapzation - Set Min/Max Precision


Previous Page Next Page  

In this example, we re setting min and max digits for both integer as well as fractional part of a number.

IOTester.java

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

pubpc class I18NTester {
   pubpc 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));
   }
}

Output

It will print the following result.

234.763
Print