What is wrong with this lowercase format (different behavior on the simulator and device)?

I have this block of code executed when a number is pressed:

    NSString *currentValue = [@"" stringByAppendingFormat:@"%.02f", [[[[[textField text] stringByReplacingOccurrencesOfString:@"." withString:@""] stringByReplacingOccurrencesOfString:@"," withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""] doubleValue]/100.0f];
            //I am using this to obtain always a number with 2 decimals.

    NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
    [f setNumberStyle:NSNumberFormatterDecimalStyle];
    [f setMinimumFractionDigits:2];
    [f setMaximumFractionDigits:2];
    [f setGroupingSeparator:@" "];

    NSNumber *currentNumberValue = [f numberFromString:currentValue];
    NSLog(@"1: %@", currentValue);
    NSLog(@"2: %@", [currentNumberValue stringValue]);

Now, if I run this in the simulator and press 3, I get the following results:

1: 0.03
2: 0.03

If I run it on the device, I have:

1: 0.03
2: 0

Thus, basically the generated number on the device is 0.
I also noticed that on the simulator I get " . " As a decimal separator, and on the device I have " , ".

And because of this, he will never be further. Any number I click is still 0.

What is the problem?

+3
source share
2

, -, ( ) , , . , alloc init :

[f setDecimalSeparator:@"."];

setLocale ( , ).

+2

:

NSString *currentValue = [textField text];
float currentFloat = [currentValue floatValue];
NSLog(@"%.2f",currentFloat); //string representation of floatValue
NSLog(@"%@",currentValue); //string currentValue
0

Source: https://habr.com/ru/post/1771572/


All Articles