표와 소스를 참고해서 이해하기!
public class exmaple {
static DecimalFormat df;
public static void main(String[] args) {
double x = 12345.67891;
double y = 0.00012;
df = new DecimalFormat("0");
System.out.println(df.format(x)); //12346
System.out.println(df.format(y)); //0
df = new DecimalFormat("0.0");
System.out.println(df.format(x)); //12345.7
System.out.println(df.format(y)); //0.0
df = new DecimalFormat("000000.000000");
System.out.println(df.format(x)); //012345.678910
System.out.println(df.format(y)); //000000.000120
df = new DecimalFormat("######.#######");
System.out.println(df.format(x)); //12345.67891
System.out.println(df.format(y)); //0.00012
df = new DecimalFormat("0.0%");
System.out.println(df.format(x)); //1234567.9%
System.out.println(df.format(y)); //0.0%
df = new DecimalFormat("0%");
System.out.println(df.format(x)); //1234568%
System.out.println(df.format(y)); //0%
}
}
728x90
반응형