Convert string to float in Objective-C

前端 未结 2 1526
迷失自我
迷失自我 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:10
    your_float = [your_string floatValue];
    

    EDIT:

    try this:

      NSLog(@"float value is: %f", your_float);
    
    0 讨论(0)
  • 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;
    
    0 讨论(0)
提交回复
热议问题