Morning All:
I'm using NSDecimalNumbers for arithmetic in my application. I'm having some problems with rounding. If I want to do something like:
25 / 99 * 99 - 25. Obviously it's a repeating decimal and there's going to be some change left at the end of the application. After the 'divide', by result is:
0.252525252525252525252525252525252526
After the multiply:
25.000000000000000000000000000000000074
And after the subtraction:
0.000000000000000000000000000000000074
I'm using a behaviour defined as follows to try and eliminate these rounding errors
aHandler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundUp
scale:kRoundingScale <= 36
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:NO];I've tried NSDecimalNoScale to try and see what that might change, and when I do the multiply, I get the following result:
24.9999999999999999999999999999999999998
The divide returns:
0.25252525252525252525252525252525252525.
Can someone provide some insight as to how to best define a rounding mode to best eliminate the extraneous bits at the end of a calculation?
Thanks in advance for your time
Best Regards
John