Skip to content

Instantly share code, notes, and snippets.

View AliaksandrHabrusevich's full-sized avatar

Aliaksandr Habrusevich AliaksandrHabrusevich

View GitHub Profile
@AliaksandrHabrusevich
AliaksandrHabrusevich / Int+Extenstion.swift
Created June 16, 2020 22:26 — forked from gbitaudeau/Int+Extenstion.swift
iOS solution to convert large numbers to smaller format. See : http://stackoverflow.com/a/35504720/1661338
extension Int {
func formatUsingAbbrevation () -> String {
let numFormatter = NSNumberFormatter()
typealias Abbrevation = (threshold:Double, divisor:Double, suffix:String)
let abbreviations:[Abbrevation] = [(0, 1, ""),
(1000.0, 1000.0, "K"),
(100_000.0, 1_000_000.0, "M"),
(100_000_000.0, 1_000_000_000.0, "B")]