+ 10
I need One-liners here !
Hi everyone, Someone can tell me how can we reduce the number of decimals of a float value ? Example: For an angle (45): cos (45) = 0.70710678118 Desired output: cos (45) = 0.707 (3 decimals) Thank you.
3 Answers
+ 11
Thanks to you !
+ 8
You can also work with the round() function. Example:
print(round(0.1234567, 3))
# prints 0.123
+ 3
cout << setprecision(3) << fixed << showpoint;
cout << cos (45);