Module:NumberFormater
From IdleOn MMO Wiki
Abbreviation | Name | Value | Equivalent |
---|---|---|---|
K | Thousand or Kilodillion | 10^3 | |
M | Million | 10^6 | |
B | Billion | 10^9 | |
T | Trillion | 10^12 | |
Qa | Quadrillion | 10^15 | |
Qi | Quintillion | 10^18 | |
Sx | Sextillion | 10^21 | |
Sp | Septillion | 10^24 | |
O | Octillion | 10^27 | |
No | Nonillion | 10^30 | |
D | Decillion | 10^33 | |
Udc | Undecillion | 10^36 | |
Dd | Duodecillion | 10^39 | |
Tdc | Tredecillion | 10^42 | |
Qt | Quattuordecillion | 10^45 | |
Qd | Quindecillion | 10^48 | |
Sd | Sexdecillion | 10^51 | |
St | Septendecillion | 10^54 | |
Od | Octodecillion | 10^57 | |
Nm | Novemdecillion | 10^60 | |
Vg | Vigintillion | 10^63 | |
Uvg | Unvigintillion | 10^66 | |
Dvg | Duovigintillion | 10^69 | |
Tvg | Tresvigintillion or Trevigintillion | 10^72 | |
Qav | Quattuorvigintillion | 10^75 | |
Qvg | Quinvigintillion | 10^78 | |
Svg | Sexvigintillion or Sesvigintillion | 10^81 | |
Spv | Septemvigintillion or Septenvigintillion | 10^84 | |
Ovg | Octovigintillion | 10^87 | |
Nvg | Novemvigintillion or Novenvigintillion | 10^90 | |
Tg | Trigintillion | 10^93 | |
Ut | Untrigintillion | 10^96 | |
Dt | Duotrigintillion | 10^99 | |
Reamining will follow e# notation. |
* Sources from an external Github site.
local p = {}
local NumberParser = require('Module:NumberParser')
local UNIT_EXPONENTS = {
'K',
'M',
'B',
'T',
'Q',
'QQ',
'S',
'SP',
'O',
'N',
'D'
}
function p.main(frame)
local numstr = frame.args[1]
if numstr == "Lots" then
return numstr
end
if tonumber(numstr) == nil then
numstr = NumberParser.parse(numstr)
if tonumber(numstr) == nil then
return "<BAD NUMBER>"
end
end
return p.formatnumber(numstr)
end
function p.formatnumber(arg)
-- how many digts are after the first digit divided by 3.
local unit = math.floor((arg:len() - 1) / 3)
if unit == 0 then
return arg
end
local n = string.format("%.1f", tonumber(arg) / math.pow(10, unit*3))
return string.format("%s %s", n, UNIT_EXPONENTS[unit])
end
function p.formatwithseperator(arg)
local ret = ''
-- 30000
-- Iterate from the end and add in commas.
while arg:len() > 3 do
ret = "," .. arg:sub(-3) .. ret
arg = arg:sub(1, -4)
end
-- Prepend remaining digits.
ret = arg .. ret
return ret
end
return p