English 中文(简体)
JAVA I18N - Set Rounding Mode
  • 时间:2024-09-17

Java Internapzation - Set Rounding Mode


Previous Page Next Page  

In this example, we re showcasing Rounding Mode.

IOTester.java

import java.math.RoundingMode;
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.setMinimumFractionDigits(0);
      numberFormat.setMaximumFractionDigits(0);

      System.out.println(numberFormat.format(99.50));

      numberFormat.setRoundingMode(RoundingMode.HALF_DOWN);

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

Output

It will print the following result.

100
99
Print