How to read the entire value of a double using cin?

前端 未结 1 753
小鲜肉
小鲜肉 2021-01-18 06:34
long double m;
cout << \"enter double: \"; cin >> m;
cout << \"m = \" << m <

Input:

enter double: 1.546

1条回答
  •  终归单人心
    2021-01-18 07:01

    You have read the whole value of the double. The problem is with the cout. It by default rounds the value to 6 digits after the decimal point.

    To set the precision cout uses, use setprecision from :

    #include 
    #include 
    
    using namespace std;
    
    int main() {
        long double d;
        cin >> d;
        cout << setprecision(10) << d << endl;
        return 0;
    }
    

    0 讨论(0)
提交回复
热议问题