如果用float或者double计算精度不准确的话,可用NSDecimalNumber进行加减乘除
NSDecimalNumber* n1 = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f",d1]];
NSDecimalNumber* n2 = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f",d2]];
NSDecimalNumber* n3 = [n1 decimalNumberByMultiplyingBy:n2];
网友评论