I use NSLengthFormatter to show the correct entity, e.g. meters, feet, yards, etc.
The method works, but I do not get the correct number of fractional digits.
let distance = getDistanceAsDouble()
let format = String(format: "%.1f",distance)
if let formattedDouble = Double(format) {
let lengthFormatter = NSLengthFormatter()
let formattedDistance = lengthFormatter.stringFromMeters(formattedDouble)
lbl.text = "\(formattedDistance)"
}
I googled, but I can not find how to configure NSLengthFormatter. NSNumberFormatter has properties like numberStyleor maximumFractionDigitis, but NSLengthFormatter does not ... or?
I tried using formattedDistancein Double to use again String(format: "".... This does not work because it formattedDistancecontains "yd" (or another object).
How can I fix this problem?
source
share