?? testnumberformat.java
字號:
import java.util.*;
import java.text.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestNumberFormat
{
public static void main(String[] args)
{
//需要被格式化的數(shù)字
double db = 1234000.567;
//創(chuàng)建四個Locale,分別代表中國、日本、德國、美國
Locale[] locales = {Locale.CHINA, Locale.JAPAN, Locale.GERMAN, Locale.US};
NumberFormat[] nf = new NumberFormat[12];
//為上面四個Locale創(chuàng)建12個NumberFormat對象
//每個Locale分別有通用格式器、百分比格式器、貨幣格式器
for (int i = 0 ; i < locales.length ; i++)
{
nf[i * 3] = NumberFormat.getNumberInstance(locales[i]);
nf[i * 3 + 1] = NumberFormat.getPercentInstance(locales[i]);
nf[i * 3 + 2] = NumberFormat.getCurrencyInstance(locales[i]);
}
for (int i = 0 ; i < locales.length ; i++)
{
switch (i)
{
case 0:
System.out.println("-------中國的格式--------");
break;
case 1:
System.out.println("-------日本的格式--------");
break;
case 2:
System.out.println("-------德國的格式--------");
break;
case 3:
System.out.println("-------美國的格式--------");
break;
}
System.out.println("通用數(shù)值格式:" + nf[i * 3].format(db));
System.out.println("百分比數(shù)值格式:" + nf[i * 3 + 1].format(db));
System.out.println("貨幣數(shù)值格式:" + nf[i * 3 + 2].format(db));
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -