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,567
  • 18
  • 67
  • 116

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
  • 34,719
  • 24
  • 185
  • 251
taskinoor
  • 44,735
  • 12
  • 114
  • 137
17

Like so:

float value = [someNSNumber floatValue];