I am trying to modernize my API calls and want to utilize NSMassFormatter
. The problem is simple. I can\'t get any output (aiming for imperial locale). NSMeas
The formatter does not perform any conversions. It merely formats a quantity. A gram is still a gram in any language.
However, NSMassFormatter does provide a convenience method based on kilograms. So for example:
let grams = 62453.0
let measurement = Measurement(value: grams, unit: UnitMass.grams)
let kilos = measurement.converted(to: .kilograms)
let formatter = MassFormatter()
formatter.isForPersonMassUse = true
let s = formatter.string(fromKilograms: kilos.value)
print(s) // "137.685 lb” on my machine