개인 공부/C++
소수점 반올림 출력 fixed setprecision
_h.j
2024. 6. 14. 13:13
728x90
fixe와 setprecision(n) 함께 쓰면 n+1 번째 소수점에서 반올림해서 n자리 까지 출력
아래 예제에선 넷째 자리에서 반올림해서 셋째 자리 까지 출력
#include <iomanip> //setprecision 헤더
#include <iostream>
int main(){
cout << fixed << setprecision(3) << 123.12555 << endl
//출력
// 123.126
}
728x90