+ 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.

8th Mar 2018, 12:07 AM
Med Arezki
Med Arezki - avatar
3 Respuestas
+ 11
Thanks to you !
8th Mar 2018, 12:40 AM
Med Arezki
Med Arezki - avatar
+ 8
You can also work with the round() function. Example: print(round(0.1234567, 3)) # prints 0.123
8th Mar 2018, 12:35 AM
Pedro Demingos
Pedro Demingos - avatar
+ 3
cout << setprecision(3) << fixed << showpoint; cout << cos (45);
8th Mar 2018, 2:46 AM
‎ ‏‏‎Anonymous Guy