Nice - thanks for letting me know.
It is currently May 11th, 2024, 11:58 am
Questions About Calc Measure
-
- Rainmeter Sage
- Posts: 7214
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
-
- Developer
- Posts: 22632
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Questions About Calc Measure
Yeah, my original Lua was intended to be used with the day of the month...
Here is a more robust example:
As written, requires an integer, although it wouldn't necessarily need to...
Here is a more robust example:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=100
HighBound=99999
UpdateRandom=1
UpdateDivider=5
[MeasureBigNumber]
Measure=String
String=13452345645670392874958343
[Lua]
Measure=Script
ScriptFile=NumbersToWords.lua
Disabled=1
[MeterDisplayRandom]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
InlineSetting=Case | Sentence
Text=[MeasureRandom]#CRLF#[&Lua:ConvertNumToWords('[&MeasureRandom]')]
[MeterDisplayBigNumber]
Meter=String
Y=10R
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
DynamicVariables=1
InlineSetting=Case | Sentence
Text=[MeasureBigNumber]#CRLF#[&Lua:ConvertNumToWords('[&MeasureBigNumber]')]
As written, requires an integer, although it wouldn't necessarily need to...
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 ConvertNumToWords(arg)
-- Convert a number to words
-- Original Author: Nick Gammon
-- Date: 18th March 2010
-- See: http://www.gammon.com.au/forum/?id=10155
-- preliminary sanity checks
s = tostring(arg)
if not type(tonumber(s)) == "number" then
print("Not a number")
return 0
end
if string.match(s, "-") then
negPrefix = "negative "
s = string.gsub(s, "-", "")
else
negPrefix = ""
end
if #s == 0 then
print("No number supplied")
return 0
elseif #s > 66 then
print("Number too big to convert to words")
return 0
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 negPrefix .. (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.
-
- Rainmeter Sage
- Posts: 16209
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Questions About Calc Measure
Ok, this explains why it didn't properly work in any circumstances.
-
- Rainmeter Sage
- Posts: 7214
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Questions About Calc Measure
Yes, that's a better example to emphasize Lua's usefulness. Not the best, as regex could probably do reasonably well here too (I know, right?), but much better than the previous one. Oh, and I love your wallpaper, haha! That's one big ugly dinosaur you have there...
-
- Developer
- Posts: 22632
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Questions About Calc Measure
You do not have the required permissions to view the files attached to this post.
-
- Rainmeter Sage
- Posts: 7214
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
-
- Posts: 36
- Joined: October 21st, 2018, 2:55 am
-
- Developer
- Posts: 22632
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
-
- Posts: 36
- Joined: October 21st, 2018, 2:55 am
Re: Questions About Calc Measure
Thank You very much.jsmorley wrote: ↑March 10th, 2020, 10:40 am https://forum.rainmeter.net/viewtopic.php?f=27&t=22696#p119763
-
- Rainmeter Sage
- Posts: 7214
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Questions About Calc Measure
Not quite similar, but really flexible and powerful (and now without flickering, due to the custom tooltips ):
P.S. For the Rainmeter feed, jsmorley's one is better than mine, because it only displays the items' title. You do not have the required permissions to view the files attached to this post.