I'm taking a math oriented programming class and this assignment involves some payments. If a calculation for a payment comes out to something like this: 100.251, I want to round that value up to 100.26. Using fixed and setprecision(2) uses normal rounding rules.
I'm thinking it involves the 'ceil' function but it seems to be rounding up my values to the nearest whole integer. Any ideas?
You want to round up to a more significant decimal place, in your stated case hundreths. Simply multiply by 100, use ceil() to round up and then divide by 100.
1 2 3 4 5 6 7 8 9
#include <iostream>
#include <cmath>
int main()
{
std::cout << "100.251 rounded off to hundredths is " << (ceil((100.251 * 100)) / 100) << "\n";
return 0;
}