English 中文(简体)
JAVA I18N - Format Percentages
  • 时间:2024-09-17

Java Internapzation - Format Percentages


Previous Page Next Page  

In this example, we re formatting numbers in percentage format.

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.getPercentInstance(enLocale);

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

Output

It will print the following result.

76%
Print