cout 소수점 고정

실수의 소수점 자리수를 고정하는 법

cout으로 실수를 출력할 때, 소수점 자리수를 고정하여 출력할 수 있습니다.

#include <iostream>
using namespace std;
int main(){
    double a = 3.141592;
    cout << fixed;
    cout.precision(3);
    cout << a; // 3.142
}

© 2018. All rights reserved.

Powered by Hydejack v8.5.2