2

When I wanted to trunc a floating number for showing in a label in Objective-C I could just use LABEL.text = [NSString stringWithFormat:@"%.3f", FLOAT];

Though I can't find how to do so in Swift.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Gary
  • 1,020
  • 1
  • 8
  • 20

1 Answers1

4

The old NSString format is still available. You can use that.

let myfloat : Float = 1.23
LABEL.text = NSString(format: "%.3f", myfloat)
Unapiedra
  • 15,037
  • 12
  • 64
  • 93