+ 1
Can I set variables to 1 decimal place?
I am tinkering again and I have found some code online: cout << fixed << setprecision(1)<< MyFloat; but this only applies to that one instance at that one time. Is there any way I can set a default in the programme so it knows to always use 1dp with these variables? Thank you
4 Antworten
+ 4
Simply start your code with this :
cout.setf(ios::fixed);
cout.precision(1);
//Now its the default precision, one digit after the decimal, always, wont count significant digits...
// General -
stream_name.setf(ios::ios_flag_to_use);
stream_name.precision(default_precision_value);
+ 9
Yeah, if you only need 1dp precision, just store the value as 1dp to your variable, instead of manipulating output for each time.
+ 1
Thank you. that is great.