我有
NSString *strAmount = @"10.00";
NSInteger totalAmount = totalAmount + [strAmount integerValue];
输出
totalAmount = 80
但我希望输出为totalAmount = 10
答案 0 :(得分:1)
totalAmount
不应该是指针类型。totalAmount
”在其自己的初始化用
替换你的代码NSString *strAmount = @"10.00";
NSInteger totalAmount = 0;
totalAmount = totalAmount + [strAmount integerValue];
NSLog(@" %ld",(long)totalAmount);
输出= 10
答案 1 :(得分:0)
为什么你做了指向int的指针?
NSInteger totalAmount 0;
totalAmount = totalAmount + [strAmount integerValue];
答案 2 :(得分:0)
将NSInterger *total
替换为NSInteger total
或将NSInteger转换为int(基于C)
NSString *strAmount = @"10.00";
NSInteger totalAmount = 0;
totalAmount = totalAmount + [strAmount integerValue];