Skip to content

Instantly share code, notes, and snippets.

@nefftd
Created August 16, 2014 03:02
Show Gist options
  • Save nefftd/42f731409d32fd85ed90 to your computer and use it in GitHub Desktop.
Save nefftd/42f731409d32fd85ed90 to your computer and use it in GitHub Desktop.
local suf = {'k','M','B','T'}
local function clean_format(val)
local m = math.min(#suf,math.floor(math.log10(val)/3))
local n = val / 1000 ^ m
local fmt = (m == 0 or n >= 10) and '%d%s' or '%.1f%s'
return fmt:format(n,suf[m] or '')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment