0

How to set two decimal point after calculate ?

Example : After calculation I got 14.445. But, I want to convert it 14.45. What should I do ?

10th Apr 2020, 10:05 AM
Socheat Sorng
Socheat Sorng - avatar
3 Antworten
+ 3
You can use std::setprecision() to control the number of decimal places: https://en.cppreference.com/w/cpp/io/manip/setprecision
10th Apr 2020, 10:10 AM
Shadow
Shadow - avatar
+ 14
You can use the built-in function setprecision ex: float pi = 3.141590 cout << fixed << setprecision(2) << pi; setprecision() when used with fixed provides you with precision to float values to the decimal number mentioned.
10th Apr 2020, 10:12 AM
Nova
Nova - avatar
+ 1
Shadow Nova Thanks for your help.
10th Apr 2020, 1:01 PM
Socheat Sorng
Socheat Sorng - avatar