반응형

 

DecimalFormat를 이용하여

123,234.44 이런식으로 ,를 자동으로 찍어주고 소숫점의 .을 찍어주는 역할을 하는 기본적인 로직이다.

 

import java.text.DecimalFormat;

public class subject {
    public static void main(String[] args) {
        DecimalFormat formatter = new DecimalFormat("###,###.##");

        float i = 1.52f;
        while(i <= 1000000000) {
            i *= 17;
            System.out.println(formatter.format(i));
        }
    }
}

 

25.84
439.28
7,467.76
126,951.91
2,158,182.5
36,689,104
623,714,752
10,603,150,336

 

더 많은 포멧들은 아래에서 확인할 수 있다.

https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html#numberpattern

 

Customizing Formats (The Java™ Tutorials > Internationalization > Formatting)

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See JDK Release Notes for information about new fe

docs.oracle.com

 

반응형