[ACCEPTED]-How i can convert NSString to long value?-long-integer

Accepted answer
Score: 59

You can use NSString methods intValue longLongValue.

0

Score: 24

For a small number like this "100023", this 9 is acceptable with 'longlongvalue'. However, if 8 the number digits have more than >10 in 7 which commonly regard as the use case for 6 long value. Then, you will run in into this 5 problem, such as:

String value "86200054340607012013"

do

@"86200054340607012013" integerValue or intValue 

you will produce this 4 in the print statement

2147483647 

if you do

@"86200054340607012013" longlongvalue

you will 3 produce this in the print statement

9223372036854775807

This 2 works for me and print out the expected 1 number.

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:@"2394739287439284734723"];
NSLog(@"longlong: %llu", [myNumber longLongValue]);   
Score: 14

Use this:

    yourLong = [yourString longLongValue];

0

Score: 2

you can use the doubleValue Method to avoid lose of 1 precision warnings

Score: 0

The answer is :

float floatId = [strID floatValue];

0

More Related questions