I\'m trying to write a function to present thousands and millions into K\'s and M\'s For instance:
1000 = 1k
1100 = 1.1k
15000 = 15k
115000 = 115k
1000000 =
if you want in lacs :
extension Int {
func shorted() -> String {
if self >= 1000 && self < 10000 {
return String(format: "%.1fK", Double(self/100)/10).replacingOccurrences(of: ".0", with: "")
}
if self >= 10000 && self < 100000 {
return "\(self/1000)k"
}
if self >= 100000 && self < 1000000 {
return String(format: "%.1fL", Double(self/10000)/10).replacingOccurrences(of: ".0", with: "")
}
if self >= 1000000 && self < 10000000 {
return String(format: "%.1fM", Double(self/100000)/10).replacingOccurrences(of: ".0", with: "")
}
if self >= 10000000 {
return "\(self/1000000)M"
}
return String(self)
}
}