JKBigInteger
JKBigInteger copied to clipboard
JKBigDecimal subtraction bug
1.1 - 1.01 = 9.09, instead of 0.09
JKBigDecimal *bigDecimal = [JKBigDecimal decimalWithString:@"1.1"]; bigDecimal = [bigDecimal subtract:[JKBigDecimal decimalWithString:@"1.01"]]; NSLog(@"%@", bigDecimal.stringValue); // 1.1 - 1.01 = 9.09, instead of 0.09
Please change current
- (id)subtract:(JKBigDecimal *)bigDecimal
{
...
}
to this:
- (id)subtract:(JKBigDecimal *)bigDecimal
{
JKBigDecimal *newBigDecimal = [self add:[bigDecimal multiply:[JKBigDecimal decimalWithString:@"-1"]]];
return newBigDecimal;
}