0
how can I control the no. of numbers after decimal point?
for example printing .12 instead of .123
2 Answers
+ 1
u can use std::setprecision(2) -- include iomanip.h
or std::round(.5) -- include math.h. there is also floor and truncate function.
u can write ur own function or import any 3rd party written function and use.
0
The question is: What for? If it's just for output and you would like to keep the fraction part in the variable untouched, use stream modifiers that just modify how cout prints them to the standard output. If you really want less precision, you can either chose float or double or cut the fraction part off via mathematical operations.