价格计算的精度

如果用float或者double计算精度不准确的话,可用NSDecimalNumber进行加减乘除

NSDecimalNumber* n1 = [NSDecimalNumber       decimalNumberWithString:[NSString    stringWithFormat:@"%f",d1]];

    NSDecimalNumber* n2 = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f",d2]];

    NSDecimalNumber* n3 = [n1 decimalNumberByMultiplyingBy:n2];

你可能感兴趣的:(价格计算的精度)