I just want to ask about setprecision because I\'m a bit confused.
here\'s the code:
#include
#include
using namesp
There is no reason to expect that any of the constants in your post can be represented exactly using the floating-point system. As a consequence, the exact halves that you have may no longer be exact halves once you store them in a double
variable (regardless of how the iostreams are meant to round such numbers.)
The following code illustrates my point:
#include
#include
using namespace std;
int main()
{
double rate = 1.115;
cout << fixed << setprecision(20) << rate;
}
Output:
1.11499999999999999112
I would recommend taking a look at the FAQ.