26

I need to multiply the value of an nsnumber by a float but they are of course incompatible types. How can I cast the nsnumber to a float?

dubbeat
  • 7,706
  • 18
  • 70
  • 122

2 Answers2

57
float result = [myNSNumber floatValue] * myFloat;

Please check the "Accessing Numeric Values" section from NSNumber class reference for converting to other types.

Cœur
  • 37,241
  • 25
  • 195
  • 267
taskinoor
  • 45,586
  • 12
  • 116
  • 142
17

Like so:

float value = [someNSNumber floatValue];