In my book it said that i can use this
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
But what if i want to round it off to the nearest 0.50?
like double Cash = 10.34 will be 10.50
Thanks.
Printable View
In my book it said that i can use this
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
But what if i want to round it off to the nearest 0.50?
like double Cash = 10.34 will be 10.50
Thanks.
I/O functions don't do math. Just round it manually.
Code:double round(double number)
{
double change = number - (int)number;
number -= change;
if(change < 0.25) change = 0;
else if(change > 0.75) change = 1;
else change = 0.50;
return number + change;
}