I would like to format a height in a human readable way and I want to check I am not reinventing the wheel.
So, say I want to output 5' 1" 1/8
Does the Foundation framework do this out of the box or do I need to roll my own? I'm not asking anyone to do the rolling, just that I'm not missing the intended way of doing this.
import UIKit
let feet = Measurement<UnitLength>(value: 5, unit: .feet)
print(feet)
let inches = Measurement<UnitLength>(value: 1.125, unit: .inches)
print(inches)
let height = (feet + inches).converted(to: .feet)
print(height)
// I want to output 5' 1" 1/16
let formatter = MeasurementFormatter()
formatter.locale = Locale(identifier: "en_US")
formatter.unitOptions = .naturalScale
formatter.unitStyle = .long
print(formatter.string(from: height))
formatter.unitStyle = .medium
print(formatter.string(from: height))
formatter.unitStyle = .short
print(formatter.string(from: height))
Output
5.0 ft
1.125 in
5.09375 ft
61.125 inches
61.125 in
61.125″