I'd like to print a string based on a Measurement but limit it to 2 digits. I am using the MeasurementFormatter for this.
var beans:Measurement = Measurement(value: 20.22321, unit: UnitMass.milligrams) // "20.22321 mg"
let formatter = MeasurementFormatter()
formatter.numberFormatter.maximumFractionDigits = 2
let label = formatter.string(from: beans) // 0 lb
I expected 20.22 mg
as a results, not 0 lb
. Where's my mistake?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…