Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=100
HighBound=9999
UpdateRandom=1
UpdateDivider=5
OnUpdateAction=[!UpdateMeasure MeasureRandomLua][!UpdateMeter *][!Redraw]
[MeasureRandomLua]
Measure=Script
ScriptFile=NumbersToWords.lua
NumbertToConvert=[MeasureRandom]
DynamicVariables=1
UpdateDivider=-1
[MeasureREALLYBigNumber]
Measure=String
String=83974367238613429496729523412345647
[MeasureREALLYBigNumberLua]
Measure=Script
ScriptFile=NumbersToWords.lua
NumbertToConvert=[MeasureREALLYBigNumber]
DynamicVariables=1
UpdateDivider=-1
[MeterDisplayRandom]
Meter=String
MeasureName=MeasureRandom
MeasureName2=MeasureRandomLua
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
InlineSetting=Case | Sentence
Text=%1#CRLF#%2
[MeterDisplayBigNumber]
Meter=String
Y=10R
MeasureName=MeasureREALLYBigNumber
MeasureName2=MeasureREALLYBigNumberLua
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
ClipString=2
ClipStringW=600
InlineSetting=Case | Sentence
Text=%1#CRLF#%2
Code: Select all
function Initialize()
inverse_units = {
"vigintillion ", -- 10^63
"novemdecillion ", -- 10^60
"octodecillion ", -- 10^57
"septendecillion ", -- 10^54
"sexdecillion ", -- 10^51
"quindecillion ", -- 10^48
"quattuordecillion ",-- 10^45
"tredecillion ", -- 10^42
"duodecillion ", -- 10^39
"undecillion ", -- 10^36
"decillion ", -- 10^33
"nonillion ", -- 10^30
"octillion ", -- 10^27
"septillion ", -- 10^24
"sextillion ", -- 10^21
"quintillion ", -- 10^18
"quadrillion ", -- 10^15
"trillion ", -- 10^12
"billion ", -- 10^9
"million ", -- 10^6
"thousand ", -- 10^3
} -- inverse_units
inverse_numbers = {
"one ",
"two ",
"three ",
"four ",
"five ",
"six ",
"seven ",
"eight ",
"nine ",
"ten ",
"eleven ",
"twelve ",
"thirteen ",
"fourteen ",
"fifteen ",
"sixteen ",
"seventeen ",
"eighteen ",
"nineteen ",
"twenty ",
[30] = "thirty ",
[40] = "forty ",
[50] = "fifty ",
[60] = "sixty ",
[70] = "seventy ",
[80] = "eighty ",
[90] = "ninety ",
} -- inverse_numbers
end
function Update()
numArgs = SELF:GetOption('NumbertToConvert')
return(ConvertNumToWords(numArgs))
end
function ConvertNumToWords(n)
-- Convert a number to words
-- Author: Nick Gammon
-- Date: 18th March 2010
-- Example of use:
-- words = ConvertNumToWords('94921277802687490518')
-- Return nil and an error message so you can check for failure,
-- or assert, eg. words = assert(ConvertNumToWords('2687490518'))
-- See: http://www.gammon.com.au/forum/?id=10155
s = tostring(n)
-- preliminary sanity checks
c = string.match (s, "%D")
if c then
return nil, "Non-numeric digit '" .. c .. "' in number"
end -- if
if #s == 0 then
return nil, "No number supplied"
elseif #s > 66 then
return nil, "Number too big to convert to words"
end -- if
-- make multiple of 3
while #s % 3 > 0 do
s = "0" .. s
end -- while
result = ""
start = #inverse_units - (#s / 3) + 2
for i = start, #inverse_units do
group = tonumber(string.sub (s, 1, 3))
if group > 0 then
result = result .. ConvertTo999 (group) .. inverse_units [i]
end -- if not zero
s = string.sub(s, 4)
end -- for
result = result .. ConvertTo999(tonumber (s))
if result == "" then
result = "zero"
end -- if
return (string.gsub(result, " +$", "")) -- trim trailing spaces
end -- ConvertNumToWords
function ConvertTo999(n)
if n <= 0 then
return ""
end -- if zero
hundreds = math.floor(n / 100)
tens = math.floor(n % 100)
result = ""
-- if over 99 we need to say x hundred
if hundreds > 0 then
result = inverse_numbers[hundreds] .. "hundred "
if tens == 0 then
return result
end -- if only a digit in the hundreds column
-- to have "and" between things like "hundred and ten"
-- uncomment the next line
result = result .. "and "
end -- if
-- up to twenty it is then just five hundred (and) fifteen
if tens <= 20 then
return result .. inverse_numbers[tens]
end -- if
-- otherwise we need: thirty (something)
result = result .. inverse_numbers[math.floor(tens / 10) * 10]
-- get final digit (eg. thirty four)
local digits = math.floor(n % 10)
-- to put a hyphen between things like "forty-two"
-- uncomment the WITH HYPHEN line and
-- comment out the NO HYPHEN line
if digits > 0 then
-- result = result .. inverse_numbers [digits] -- NO HYPHEN
result = string.sub(result, 1, -2) .. "-" .. inverse_numbers[digits] -- WITH HYPHEN
end -- if
return result
end -- ConvertTo999