Reputation: 559
I am trying to program a converter in iOS.
The user enters values into textfields, and the values are converted.
The results are finally given back to the user.
The output has to be in a locale decimal format, which works.
Also, the output has to be printed in exponent form, which works.
Problem: I need both exponent form and decimal form.
The following code explains what works.
//formatting
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setNumberStyle: NSNumberFormatterDecimalStyle];
//formattiing
float myFloat=0.01;
NSNumber *myNumber =[[NSNumber alloc]initWithFloat:myFloat];
NSString *myString =[formatter stringFromNumber:myNumber];
NSLog(@"Locale: %@", formatter.locale.localeIdentifier);
NSLog(@"myFloat = %g", myFloat);
NSLog(@"myNumber = %.2e",[myNumber floatValue]);
NSLog(@"myString = %@", myString);
//output
Locale: nb_NO
myFloat = 0.01
myNumber = 1.00e-02
myString = 0,01
What does NOT work. I need exponent and decimalformatter in one!
I want this output:
myString = 1,00e-2
Anybody got a clue?
Upvotes: 1
Views: 783