How to convert NSNumber objects for computational purposes?

后端 未结 1 1700
梦如初夏
梦如初夏 2021-01-11 12:03

I an developing some code in which I use a scanner to get to NSNumbers from a string, say x and y.

Now I want to compute something simple from x and y, say, z = 10.0

相关标签:
1条回答
  • 2021-01-11 12:37

    Use the "value" methods of the NSNumber class such as doubleValue.

    // Initialized to something earlier
    NSNumber * x, y;
    
    //Convert NSNumbers to double
    double xD = [x doubleValue]; 
    double yD = [y doubleValue];
    
    // You can now use regular arithmetic operators
    double zD = 10.0 / ((x + y / 60.0) / 60.0);
    
    0 讨论(0)
提交回复
热议问题