I have a problem with rounding the calculation result to two decimal places.
This is a financial calculation, and when the result includes half a penny, I expect the number to be rounded, but in fact it is rounded.
To reproduce the problem:
float raw = 16.695;
NSLog(@"All DP: %f",raw);
NSLog(@"2 DP: %.2f",raw);
Returns:
All DP: 16.695000
2 DP: 16.69
While I would expect to see:
All DP: 16.695000
2 DP: 16.70
Can anyone advise if this is by design or if (most likely) I am missing something, and if there is something that I can do to get around it. It is very important that it is rounded in this scenario.
Thanks in advance, Oli
source
share