Digit limitation from decimal point in C++

后端 未结 8 696
不思量自难忘°
不思量自难忘° 2020-12-28 16:57

I\'m new to C++. I have a double variable double a=0.1239857 and I want to limit variable a from decimal point two digits. So a will b

8条回答
  •  自闭症患者
    2020-12-28 17:10

    you could also do something like this:

    //This code will ask the user for an input, set the decimal precision to the hundredths place,  and add 4.63 to the inputted variable
    
    int banana;
    cin >> banana;
    cout << setprecision(2) << fixed << banana + 4.63; 
    

提交回复
热议问题