提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用默认格式格式化数字
import java.text.NumberFormat; import java.util.Locale; /** 时代Java公众号 - nowjava.com 提供 **/ public class Main { public static void main(String[] args){ double value = 1234567.895 ; // Default locale printFormatted(Locale.getDefault(), value); // Indian locale Locale indianLocale = new Locale("en", "IN"); printFormatted(indianLocale, value); } //nowjava.com public static void printFormatted(Locale locale, double value) { // Get number and currency formatter NumberFormat nf = NumberFormat.getInstance(locale); NumberFormat cf = NumberFormat.getCurrencyInstance(locale); System.out.println("Formatting value: " + value +