알고리즘 문제 풀다 필요해져서 찾아본 내용
예를 들어 소수점 둘째 자리까지 출력하세요
인데
답이 6.2라면 6.20을 출력해야 하는 경우에 해당
import java.io.*;
import java.text.DecimalFormat;
public class Main {
public static void main(String args[]) throws IOException, InterruptedException {
double number = 6.2;
System.out.println(number);
// 1번 방법
System.out.println(String.format("%.2f", number));
// 2번 방법
DecimalFormat form = new DecimalFormat("#.00");
System.out.println(form.format(number));
}
}

'PROGRAMMING > JAVA' 카테고리의 다른 글
| [JAVA] Array : Arrays.copyOfRange (0) | 2021.05.21 |
|---|---|
| [JAVA] Map : getOrDefault (0) | 2021.05.05 |
| [JAVA] GC(Garbage Collection) 이란? (2/2) (0) | 2021.04.12 |
| [JAVA] GC(Garbage Collection) 이란? (1/2) (0) | 2021.04.04 |
| [JAVA] 자바/JVM 메모리 구조 (0) | 2021.04.03 |