java.text.DecimalFormat()のサンプル

javaコード

import java.text.DecimalFormat;

public class Decimal {

public static void main(String[] args) {

DecimalFormat df = new DecimalFormat(“######0.00”);

double d1 = 4.23456;
double d2 = 0.0;
double d3 = 2.0;
System.out.println(df.format(d1));
System.out.println(df.format(d2));
System.out.println(df.format(d3));
}

}

結果

4.23
0.00
2.00

Comments are closed.