Convert string to float in Objective-C

前端 未结 2 1541
迷失自我
迷失自我 2020-12-02 01:28

How do I convert a string to a float in Objective-C?

I am trying to multiply a couple of strings I am getting back from JSON:

float subTotal = [[[[pu         


        
2条回答
  •  一生所求
    2020-12-02 02:18

    The proper way of doing this is

    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
    
    float value = [numberFormatter numberFromString:@"32.12"].floatValue;
    

提交回复
热议问题