DecimalFormat の四捨五入?
2007/09/20
java
DecimalFormat format = new DecimalFormat("00");
double d = 0.6;
d = 0.1;
System.out.println(d + ":" + format.format(d));
d = 0.5;
System.out.println(d + ":" + format.format(d));
d = 0.55;
System.out.println(d + ":" + format.format(d));
d = 0.545;
System.out.println(d + ":" + format.format(d));
d = 0.5445;
System.out.println(d + ":" + format.format(d));
d = 0.59;
System.out.println(d + ":" + format.format(d));
d = 0.59;
System.out.println(d + ":" + format.format(d));
double d = 0.6;
d = 0.1;
System.out.println(d + ":" + format.format(d));
d = 0.5;
System.out.println(d + ":" + format.format(d));
d = 0.55;
System.out.println(d + ":" + format.format(d));
d = 0.545;
System.out.println(d + ":" + format.format(d));
d = 0.5445;
System.out.println(d + ":" + format.format(d));
d = 0.59;
System.out.println(d + ":" + format.format(d));
d = 0.59;
System.out.println(d + ":" + format.format(d));
小数点以下を切り捨てるわけではないことに注意!!
: