I have
NSString *strAmount = @"10.00";
NSInteger totalAmount = totalAmount + [strAmount integerValue];
The output is
totalAmount = 80
but I want the output to be totalAmount = 10
I have
NSString *strAmount = @"10.00";
NSInteger totalAmount = totalAmount + [strAmount integerValue];
The output is
totalAmount = 80
but I want the output to be totalAmount = 10
totalAmount
should not be of pointer type.totalAmount
' is uninitialized when used within its own initializationreplace your code with
NSString *strAmount = @"10.00";
NSInteger totalAmount = 0;
totalAmount = totalAmount + [strAmount integerValue];
NSLog(@" %ld",(long)totalAmount);
Output = 10
why you did pointer to int?
NSInteger totalAmount 0;
totalAmount = totalAmount + [strAmount integerValue];
Replace NSInterger *total
by NSInteger total
or convert NSInteger to int (C based)
NSString *strAmount = @"10.00";
NSInteger totalAmount = 0;
totalAmount = totalAmount + [strAmount integerValue];