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
  • 88,907
  • 20
  • 222
  • 246
Gary
  • 874
  • 1
  • 6
  • 18

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
  • 13,615
  • 10
  • 59
  • 86