新学NumberFormat两种format方式

1 getCurrencyInstance

double num = 1323.526;

NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
System.out.println("US: " + defaultFormat.format(num));

Locale swedish = new Locale("sv", "SE");
NumberFormat swedishFormat = NumberFormat.getCurrencyInstance(swedish);
System.out.println("Swedish: " + swedishFormat.format(num));

换算很方便,output是:

US: $1,323.53
Swedish: 1 323,53 kr

2 getPercentaInstance : use getPercentInstance to get a format for displaying percentages. With this format, a fraction like 0.53 is displayed as 53%.

double num = 0.53;

NumberFormat defaultFormat = NumberFormat.getPercentInstance();
System.out.println(defaultFormat.format(num));

output is :

53%


你可能感兴趣的:(新学NumberFormat两种format方式)