Java Internationalization - Set Min/Max Precision



Example

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

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)); } }

Output

It will print the following result.

234.763
Advertisements