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 ?
3 Antworten
+ 3
You can use std::setprecision() to control the number of decimal places:
https://en.cppreference.com/w/cpp/io/manip/setprecision
+ 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.