I want to convert NSString to NSNumber without using numbreFromString: method? The numbreFromString: metgod is acting weirdly in 4.0. So i want to use an alternative to convert NSString to NSNumber. Please Help me....
+ (NSString *)formatText:(NSString *) text withLocalSettings:(BOOL) isLacale {
NSNumber *aNsNumber= [numberFormatter numberFromString: text];
NSString *returnString = [NSString stringWithString:[numberFormatter stringForObjectValue:aNsNumber]];
if(isLacale) {
return returnString;
}
else {
return [NSString stringWithFormat:@"%lf",[aNsNumber doubleValue]];
}
}
0
I am developing an application i need to run my app both in 3.0 and 4.0. I have a textfield where when i try to enter numbers in the textfield the behaviour is like this... IN 3.0 :- It allows to enter 7 digits and 2 fractional values (I have formatted it like this). I have formatted and localized the numbers along with the comma seperations depending on the country selected. It is working perfectly in 3.0 and 3.1.2
IN 4.0 : - It allows you to enter only 4 numbers and after entering 5th digit it is making the textfields empty.. Nothing is displayed when u enter the 5th number and when u enter the 6th number it starts from the 1st number and continues the same til 4 numbers. ex: - when u enter 1234, textfield appears - 1234 and when u enter 12345, textfield appears " ". and when u enter 6 now it starts with 6 and so on..
I am using the NSNumberFormatter and numberfromstring method to format the values entered in the textfield.
I am not able to understand why this is happening like this... Please help me...
[NSNumber numberWithInteger:[theString integerValue]];
[NSNumber numberWithDouble:[theString doubleValue]];
also floatValue, intValue, longLongValue, boolValue
Edit:
to strip out commas, use stringByReplacingOccurrencesOfString before doing the above.
theString = [theString stringByReplacingOccurrencesOfString:@"," withString:@""];
to strip out more than one character, you could get something working with componentsSeparatedByCharactersInSet.
theSet = [NSCharacterSet characterSetWith...];
theString = [[theString componentsSeparatedByCharactersInSet:theSet] componentsJoinedByString:@""];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With