0

Trying to get a SKLabelNode to show a float, but instead it only shows an integer. This is what i have at the moment:

sdrLabel.text = String(Float(NSUserDefaults.standardUserDefaults().integerForKey("TotalScore") / NSUserDefaults.standardUserDefaults().integerForKey("TotalDeath")))

I tried to type cast it to a float and present it as a string, but it still shows an int. For example 233 / 8, it shows 29.

1 Answers1

0

You are loosing precision because you are working with integers and then you cast the result to Float. You need to work with Float (or Double) when dividing those two numbers.

You can use this instead:

sdrLabel.text = String(NSUserDefaults.standardUserDefaults().doubleForKey("TotalScore") / NSUserDefaults.standardUserDefaults().doubleForKey("TotalDeath"))
Whirlwind
  • 14,286
  • 11
  • 68
  • 157