Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,55 +1,37 @@
fn NumberToWord myNum = (
local Result = ""
while myNum != 0 do (
Result += case of (
(myNum >= 1000):(myNum -= 1000; "one thousand")
(myNum > 900): (myNum -= 900 ; "nine hundred and")
(myNum == 900): (myNum -= 900 ; "nine hundred")
(myNum > 800): (myNum -= 800 ; "eight hundred and")
(myNum == 800): (myNum -= 900 ; "eight hundred")
(myNum > 700): (myNum -= 700 ; "seven hundred and")
(myNum == 700): (myNum -= 900 ; "seven hundred")
(myNum > 600): (myNum -= 600 ; "six hundred and")
(myNum == 600): (myNum -= 900 ; "six hundred")
(myNum > 500): (myNum -= 500 ; "five hundred and")
(myNum == 500): (myNum -= 900 ; "five hundred")
(myNum > 400): (myNum -= 400 ; "four hundred and")
(myNum == 400): (myNum -= 900 ; "four hundred")
(myNum > 300): (myNum -= 300 ; "three hundred and")
(myNum == 300): (myNum -= 900 ; "three hundred")
(myNum > 200): (myNum -= 200 ; "two hundred and")
(myNum == 200): (myNum -= 900 ; "two hundred")
(myNum > 100): (myNum -= 100 ; "one hundred and")
(myNum == 100): (myNum -= 100 ; "one hundred")
(myNum >= 90): (myNum -= 90 ; "ninety")
(myNum >= 80): (myNum -= 80 ; "eighty")
(myNum >= 70): (myNum -= 70 ; "seventy")
(myNum >= 60): (myNum -= 60 ; "sixty")
(myNum >= 50): (myNum -= 50 ; "fifty")
(myNum >= 40): (myNum -= 40 ; "fourty")
(myNum >= 30): (myNum -= 30 ; "thirty")
(myNum >= 20): (myNum -= 20 ; "twenty")
(myNum >= 19): (myNum -= 19 ; "nineteen")
(myNum >= 18): (myNum -= 18 ; "eighteen")
(myNum >= 17): (myNum -= 17 ; "seventeen")
(myNum >= 16): (myNum -= 16 ; "sixteen")
(myNum >= 15): (myNum -= 15 ; "fifteen")
(myNum >= 14): (myNum -= 14 ; "fourteen")
(myNum >= 13): (myNum -= 13 ; "thirteen")
(myNum >= 12): (myNum -= 12 ; "twelve")
(myNum >= 11): (myNum -= 11 ; "eleven")
(myNum >= 10): (myNum -= 10 ; "ten")
(myNum >= 9): (myNum -= 9 ; "nine")
(myNum >= 8): (myNum -= 8 ; "eight")
(myNum >= 7): (myNum -= 7 ; "seven")
(myNum >= 6): (myNum -= 6 ; "six")
(myNum >= 5): (myNum -= 5 ; "five")
(myNum >= 4): (myNum -= 4 ; "four")
(myNum >= 3): (myNum -= 3 ; "three")
(myNum >= 2): (myNum -= 2 ; "two")
(myNum >= 1): (myNum -= 1 ; "one")
)
if myNum != 0 then result += " "
fn numToEng num =
(
num = num as integer -- convert to int
local originalNumber = num -- store the initial value, to check if it was negative afterwards
num = abs num -- make positive
local numStr = num as string -- store as string to check the length
local nonFirstDigits = (if numStr.count > 3 then ((substring numStr ((if mod numStr.count 3 ==0 then 3 else mod numStr.count 3)+1) -1)) else "0") -- this is the string of the number without the beginning, i.e 123456 will give 456, 12035 will give 2035
local singleDigits = #("One","Two","Three","Four","Five","Six","Seven","Eight","Nine")
local ElevenTwenty = #("Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen")
local tens = #("Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety")
local big = #("Hundred","Thousand","Million","Billion")
local ret = "" -- this is the value to be returned
case of
(
(num == 0 ): ret += "Zero" -- number is zero
(num < 10): ret += singleDigits[num] -- number is not and smaller than 10
(num == 10): ret += tens[1] -- number is 10
(num < 20): ret += elevenTwenty[abs(10-num)] -- number is between 11 and 19
(num <= 90 and mod num 10 == 0): ret += tens[num/10] -- number is >= 20 and <= 90 and is dividable by 10
(num < 100): ret += (numToEng (floor(num/10.0)*10) +" "+ numtoEng (num-(floor(num/10.0))*10)) -- number is >= 20, < 100 and is not dividable by 10
(num < 1000): ret += (singledigits[floor(num/100) as integer] + " "+big[1]+ (if mod num 100 != 0 then (" and "+numtoeng (num-(floor(num/100.0)*100))) else "")) -- number is >= 100, < 1000
(num >= 1000): ret += -- number is >= 1000
(
numtoeng (substring numStr 1 (if mod numStr.count 3 ==0 then 3 else mod numStr.count 3)) + \
" " + big[1+((numStr.count-1)/3)] + (if nonFirstDigits as integer == 0 then "" else (if nonFirstDigits as integer < 100 then " and " else ", ")) + \
(if (mod num 1000 == 0) then "" else (numtoeng nonFirstDigits))
)
)
result
if originalNumber < 0 and (substring ret 1 8) != "Negative" do ret = ("Negative "+ret) -- if number is negative
ret = (toupper ret[1]) + (tolower (substring ret 2 -1)) -- make the first char uppercase and rest lowercase
return ret
)

View file

@ -1 +1,14 @@
NumberToWord(123)
numtoeng 0
"Zero"
numtoeng 50
"Fifty"
numtoeng 123
"One hundred and twenty three"
numtoeng -4235
"Negative four thousand, two hundred and thirty five"
numtoeng 98273
"Ninety eight thousand, two hundred and seventy three"
numtoeng -92836152
"Negative ninety two million, eight hundred and thirty six thousand, one hundred and fifty two"
numtoeng 421752302
"Four hundred and twenty one million, seven hundred and fifty two thousand, three hundred and two"