I would like to know how to round nsmeasurement after conversion from a unitmass. From Kilograms to Pounds for example and rounding to the 2nd decimal place instead of giving me the exact.
var x = Measurement(value:19, unit: UnitMass.kilograms)
x.convert(to:UnitMass.Pounds)
x.description // "41.8878639834918 lb"
I'd like it to be 41.89
By using a MeasurementFormatter
:
var x = Measurement(value:19, unit: UnitMass.kilograms)
x.convert(to:UnitMass.pounds)
x.description // 41.8878639834918 lb
let m = MeasurementFormatter()
m.numberFormatter.maximumFractionDigits = 2
m.string(from: x) // 41.89 lb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With