How to convert NSString to NSNumber without using numberfromstring

I want to convert NSString to NSNumber without using the numbreFromString method :? The numbreFromString: metgod function acts weirdly in 4.0. Therefore, 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 the application that I need to run my application in both versions 3.0 and 4.0. I have a text box where, when I try to enter numbers in the text box, the behavior looks like this ... IN 3.0: - It allows you to enter 7 digits and 2 fractional values ​​(I formatted it like this). I formatted and localized the numbers along with commas depending on the selected country. It works great in versions 3.0 and 3.1.2

IN 4.0: - 4 , 5- . , u , u 6- , 1- , 4 . ex: - u 1234, - 1234, u 12345, "". u 6, 6 ..

NSNumberFormatter numberfromstring , .

, ... , ...

+5
2
[NSNumber numberWithInteger:[theString integerValue]];
[NSNumber numberWithDouble:[theString doubleValue]];

floatValue, intValue, longLongValue, boolValue

Edit:

, stringByReplacingOccurrencesOfString, .

theString = [theString stringByReplacingOccurrencesOfString:@"," withString:@""];

, -, SeparatedByCharactersInSet.

theSet = [NSCharacterSet characterSetWith...];
theString = [[theString componentsSeparatedByCharactersInSet:theSet] componentsJoinedByString:@""];
+16

iOS4 , .

, - , , . , , (iOS4). 9.000, 9000, DecimalStyle.

- sscanf .

c lib sscanf atoi , .

#include<stdio.h>

int main(int argc, char **argv) {

   char s[] = "1.2";
   double x;

   sscanf(s, "%lf", &x);
   printf("The decimal number was %g\n\n", x);

   return 1;
}

atoi , , int.

0

All Articles