Java入門–DecimalFormatを使って数値をフォーマットする
javaコード:
import java.text.DecimalFormat;
import java.util.Locale;
public class DecimalFdtDemo {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(“*******DecimalFormcat demo***********");
DecimalFormat format = new DecimalFormat(“###,####.000");
System.out.println(format.format(3444443333456.1227222));
Locale.setDefault(Locale.US);
DecimalFormat usFmt = new DecimalFormat(“###,###.000");
System.out.println(usFmt.format(3444443333456.1227222));
DecimalFormat adPatFmt = new DecimalFormat();
adPatFmt.applyPattern(“##,###.000");
System.out.println(adPatFmt.format(3444443333456.1227));
DecimalFormat zhiFormat = new DecimalFormat();
zhiFormat.applyPattern(“0.000E0000");
System.out.println(zhiFormat.format(10000));
System.out.println(zhiFormat.format(12345678.345));
DecimalFormat perFmt = new DecimalFormat();
perFmt.applyPattern(“#0.000%");
System.out.println(perFmt.format(0.3052222));
}
}
実行結果
*******DecimalFormcat demo***********
3,4444,4333,3456.123
3,444,443,333,456.123
3,444,443,333,456.123
1.000E0004
1.235E0007
30.522%