NSDecimalNumber用法(处理CGFloat基本运算不准确问题)

声明两个  NSDecimalNumber

NSDecimalNumber *num1 = [NSDecimalNumber decimalNumberWithString:@"3.1415926"];

NSDecimalNumber *num2 = [NSDecimalNumber decimalNumberWithString:@"0.125"];

//  加法 运算函数  decimalNumberByAdding

NSDecimalNumber *jiafa = [num1 decimalNumberByAdding:num2];

NSLog(@"加法 %@", jiafa);


//  减法运算函数  decimalNumberByAdding

NSDecimalNumber *jianfa = [num1 decimalNumberBySubtracting:num2];

NSLog(@"减法 %@", jianfa);

//  乘法运算函数  decimalNumberByAdding

NSDecimalNumber *chengfa = [num1 decimalNumberByMultiplyingBy:num2];

NSLog(@"乘法 %@", chengfa);

//  除法运算函数  decimalNumberByAdding

NSDecimalNumber *chufa = [num1 decimalNumberByDividingBy:num2];

NSLog(@"除法 %@", chufa);

推荐阅读更多精彩内容