Advertisement
eytixis

formatter api (LUA)

Jul 9th, 2020
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. local formatter = {}
  2. formatter.ptable={
  3.     [1] = "f", [2] = "p", [3] = "n",[4] = "μ",
  4.     [5] = "m", [6] = "",[7] = "k", [8] = "M",
  5.     [9] = "G", [10] = "T",[11] = "P", [12] = "E",
  6.     [13] = "Z", [14] = "Y" }
  7.  
  8. function formatter.formatNumber(number, accuracy)
  9.     number = tonumber(number)
  10.     accuracy = accuracy or 1
  11.     local el = math.floor(math.log(math.abs(number), 1000))
  12.     local n = math.floor(math.abs( number ) / math.pow(10, (3*el - accuracy)))/math.pow(10, accuracy)
  13.     local fstring = nil
  14.     if (number >= 0) then
  15.         fstring = tostring(n).." "..formatter.ptable[(el+6)]
  16.     else
  17.         fstring = "-"..tostring(n).." "..formatter.ptable[(el+6)]
  18.     end
  19.     return fstring
  20. end
  21.  
  22. return formatter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement