[ACCEPTED]-How i can convert NSString to long value?-long-integer
Accepted answer
You can use NSString
methods intValue
longLongValue
.
0
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]);
Use this:
yourLong = [yourString longLongValue];
0
you can use the doubleValue Method to avoid lose of 1 precision warnings
The answer is :
float floatId = [strID floatValue];
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.