The NSNumber of the float storage. Please, not scientific notation?
Scientific notation is used in computer computer languages as the default output of very large (or very small) numbers. If you want the number to be displayed as a decimal number, you need to specify the output format (implementation depends on the language.)
Also, julesjacobs is correct. You shouldn't use FLOAT for a phone number as it is prone to rounding errors. Using INT or STRING will save you a lot of headaches.
source to share
Hey guys, what do you think about this? This seems to fulfill my goals. Only the UK at the moment will be so concerned about localization when I get the chance.
I use this to get the number
NSNumber *inputToNumber = [NSNumber numberWithLongLong:(long long)[[textField.text stringByReplacingOccurrencesOfString:@" " withString:@""] longLongValue]];
And this method formats my phone number and takes care of the previous 0.
-(NSString *)phoneNumberString:(NSNumber *)phoneNumber {
//Add a zero because NSNumber won't save a preceeding zero
NSString *telephoneString = [[NSString alloc] initWithFormat:@"0%@", [phoneNumber stringValue]];
if (telephoneString.length >= 4) {
NSString *firstPart = [[NSString alloc] initWithString: [telephoneString substringToIndex:4]];
NSString *secondPart = [[NSString alloc] initWithString: [telephoneString substringFromIndex:4]];
//Add the two parts together with a space inbetween
NSString *formattedTelephoneString = [NSString stringWithFormat:@"%@ %@", firstPart, secondPart];
//send it back to the cellForRow TableCell Method
[firstPart release];
[secondPart release];
[telephoneString release];
return formattedTelephoneString;
}
else {
return telephoneString;
}
}
Thanks for all the comments. I am going to mark the answer as the one who suggested NSString as I am afraid I will revert to using NSString for this instead of my above solution.
source to share