It is currently March 29th, 2024, 5:50 am

Numbers to Words

Skins that don't neatly fit into other categories
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Numbers to Words

Post by jsmorley »

NumbersToWords_1.0.rmskin
1.png
NumbersToWords.ini

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
NumbersToWords.lua:

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
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Numbers to Words

Post by SilverAzide »

Now if we only had a skin that could convert all the digits of pi to words, then we'd really have somethin'....
Gadgets Wiki GitHub More Gadgets...
User avatar
Bananorpion
Posts: 40
Joined: April 16th, 2017, 8:35 pm

Re: Numbers to Words

Post by Bananorpion »

SilverAzide wrote:Now if we only had a skin that could convert all the digits of pi to words, then we'd really have somethin'....
Find me a website or a file which displays all the digits of pi and I can do that in 5 minutes tops!
Bekarfel
Posts: 217
Joined: May 16th, 2012, 5:38 am

Re: Numbers to Words

Post by Bekarfel »

moshi wrote:there are many Rainmeter skins that aren't really useful, so let's add another one.
jsmorley wrote:I have good news and bad news.
First the bad news. [...] We would be happy to have this happen and would love to work with anyone who is feeling ambitious.
Now the good news.
I lied, there isn't any good news...
User avatar
Bananorpion
Posts: 40
Joined: April 16th, 2017, 8:35 pm

Re: Numbers to Words

Post by Bananorpion »

Used another, the html is "hidden" and I'm lazy.
(The "joke" was that there are always more digits anyway..)

Code: Select all

[Variables]
HowManyDigits=50

[MeasurePiParse]
Measure=Plugin
Plugin=WebParser
URL=http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html
RegExp=(3\.\d{#HowManyDigits#})
DynamicVariables=1

[MeasurePiShow]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePiParse]
StringIndex=1
Substitute="0":"zero ","1":"one ","2":"two ","3":"three ","4":"four ","5":"five ","6":"six ","7":"seven ","8":"eight ","9":"nine ",".":"point "
will give you the 50 first digits of Pi, as words.
Bekarfel
Posts: 217
Joined: May 16th, 2012, 5:38 am

Re: Numbers to Words

Post by Bekarfel »

Aww 50‽ you're just anticool. Where's your sense of adventure? your sense of excitement! crank this baby up to 11

50... Pah My grandmother can do it.. backwards, in the snow with no shoes, up hill both ways, on the computer!
moshi wrote:there are many Rainmeter skins that aren't really useful, so let's add another one.
jsmorley wrote:I have good news and bad news.
First the bad news. [...] We would be happy to have this happen and would love to work with anyone who is feeling ambitious.
Now the good news.
I lied, there isn't any good news...