iOS-Swift 单位转化
// 米 let distance = Measurement(value: 2000, unit: UnitLength.meters) // 转化为千米 let kilometers = distance.converted(to: .kilometers) // 转化为英里 let miles = distance.converted(to: .miles) // 格式化输出,保留两位小数 let kilometersFormatted = String(format: "%.2f", kilometers.value) let milesFormatted = String(format: "%.2f", miles.value) print("🐢\(kilometersFormatted) 千米\n🐢\(milesFormatted) 英里")