Geert Joos wrote:
"Bob Smith" <bo*******@marketweighton.com> schreef in bericht
round it
/B
And how do you do that, can you give me an example? I'm just a bit new in
C++
Here's one way:
#include <iostream>
#include <cmath>
using namespace std;
int
main()
{
float A = 10;
float B = 7;
float result = A / B;
float prec = 2.0;
float shift_factor = pow(10, prec);
cout << round(result * shift_factor) / shift_factor << '\n';
return 0;
}
Note that the above method is not particularly robust, elagent, or
efficient. It's probably not even accurate for arbitrary values of
'result'. Use at your own risk.
- Adam
--
Reverse domain name to reply.