반응형
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
반응형
'Basic > Java' 카테고리의 다른 글
[Java] 16진수를 10진수로, 10진수를 16진수로 변경하기 (0) | 2020.08.18 |
---|---|
Java에서 ArrayList, Array join하는 기본 방법 (0) | 2020.08.04 |
String, StringBuilder, StringBuffer 차이 (0) | 2020.02.18 |
Java 현재 시간 구하기 코드 성능 비교 (2) | 2020.01.11 |
Java 기본 정렬 및 응용 방법 (0) | 2019.12.30 |