Set Rounding Mode

Example

In this example, we’re showcasing Rounding Mode.

Open Compiler

importjava.math.RoundingMode;importjava.text.NumberFormat;importjava.util.Locale;publicclassI18NTester{publicstaticvoidmain(String[] args){Locale enLocale =newLocale("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));}}</code></pre>

Output

It will print the following result.

100
99

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *