Let my string is 77777788888 after converting to float its coming as 77777788928. But I want the accurate number
I have already tried with [str floatValue],[str doubleValue] and [str longlongValue]
Let my string is 77777788888 after converting to float its coming as 77777788928. But I want the accurate number
I have already tried with [str floatValue],[str doubleValue] and [str longlongValue]
To float
float myFloat = [myString floatValue];
To Double
double myDouble = [myString doubleValue];
NSLog(@"%.0f", [@"77777788888" floatValue]);
NSLog(@"%.0f", [@"77777788888" doubleValue]);
NSLog(@"%lld", [@"77777788888" longLongValue]);
Produces the output
77777788928
77777788888
77777788888
So if you are not getting good results, something else is wrong.
int is a 32 bit/4 byte value.
I am surprised are cannot comprehend (as of now), why you are getting that.
For now, you can use the following and this will work —
NSString *string = @"77777788888";
NSLog(@"%lld", [string longLongValue]);
I'll surely post a reply when I understand the issue.
Regards