JKBigInteger icon indicating copy to clipboard operation
JKBigInteger copied to clipboard

JKBigDecimal subtraction bug

Open OlDor opened this issue 7 years ago • 0 comments

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; }

OlDor avatar Jul 23 '17 17:07 OlDor