- Joined
- Dec 9, 2007
- Messages
- 3,096
Guys, I've been making an I2Text algorithm and it doesn't freaking work!!!
I get no errors but it just keeps saying "two billions" when i test!
It also seems to work only on 1.24b
I get no errors but it just keeps saying "two billions" when i test!
JASS:
globals
string space = " "
string line = "-"
string an = " and "
string array TEXT_NUMBER
endglobals
function InitTrig_Func takes nothing returns nothing
set TEXT_NUMBER[0] = ""
set TEXT_NUMBER[1] = "one"
set TEXT_NUMBER[2] = "two"
set TEXT_NUMBER[3] = "three"
set TEXT_NUMBER[4] = "four"
set TEXT_NUMBER[5] = "five"
set TEXT_NUMBER[6] = "six"
set TEXT_NUMBER[7] = "seven"
set TEXT_NUMBER[8] = "eight"
set TEXT_NUMBER[9] = "nine"
set TEXT_NUMBER[10] = "ten"
set TEXT_NUMBER[11] = "eleven"
set TEXT_NUMBER[12] = "twelve"
set TEXT_NUMBER[13] = "thirteen"
set TEXT_NUMBER[14] = "fourteen"
set TEXT_NUMBER[15] = "fifteen"
set TEXT_NUMBER[16] = "sixteen"
set TEXT_NUMBER[17] = "seventeen"
set TEXT_NUMBER[18] = "eighteen"
set TEXT_NUMBER[19] = "nineteen"
// -----------------------------------------
set TEXT_NUMBER[20] = "twenty"
set TEXT_NUMBER[30] = "thirty"
set TEXT_NUMBER[40] = "fourty"
set TEXT_NUMBER[50] = "fifty"
set TEXT_NUMBER[60] = "sixty"
set TEXT_NUMBER[70] = "seventy"
set TEXT_NUMBER[80] = "eighty"
set TEXT_NUMBER[90] = "ninety"
// -----------------------------------------
set TEXT_NUMBER[100] = "hundred"
set TEXT_NUMBER[101] = "hundreds"
set TEXT_NUMBER[1000] = "thousand"
set TEXT_NUMBER[1001] = "thousands"
set TEXT_NUMBER[2000] = "million"
set TEXT_NUMBER[2001] = "millions"
set TEXT_NUMBER[3000] = "billion"
set TEXT_NUMBER[3001] = "billions"
endfunction
function I2Text takes integer value returns string
local string text = I2S(value)
local integer length = StringLength(text)
local integer array numba
local integer count = 1
local string ts
local integer ti
local boolean array bool
local string result = " "
loop
exitwhen count == length
set numba[count] = S2I(SubString(text, count - 1, count))
set count = count + 1
endloop
if length > 9 then
if S2I(SubString(text, 0, length - 9)) >= 2 then
set ts = SubString(text, 0, length - 9)
set ti = StringLength(ts)
if ti > 3 then
return "THE LENGTH OF THE INTEGER TO BE CONVERTED TO TEXT IS TOO LONG. PLEASE USE A SHORTER INTEGER, LESS THAN OR EQUAL TO 12 DIGITS LENGTH."
endif
elseif S2I(SubString(text, 0, length - 9)) == 1 then
set ts = SubString(text, 0, 1)
set ti = 1
endif
if ti == 3 then
if numba[1] == 1 then
set result = result + TEXT_NUMBER[numba[1]] + TEXT_NUMBER[100]
elseif numba[1] >= 1 then
set result = result + TEXT_NUMBER[numba[1]] + TEXT_NUMBER[101]
elseif numba[1] == 0 then
set bool[1] = true
endif
if numba[2] == 1 then
if bool[1] == true then
set result = result + TEXT_NUMBER[ ( numba[2] * 10 ) + numba[3] ]
set bool[1] = false
else
set result = result + an + TEXT_NUMBER[ numba[2] * 10 ] + TEXT_NUMBER[ numba[3] ]
endif
elseif numba[2] >= 1 then
if bool[1] == true then
set result = result + TEXT_NUMBER[numba[2] * 10] + line + TEXT_NUMBER[numba[3]]
set bool[1] = false
else
set result = result + an + TEXT_NUMBER[numba[2] * 10] + line + TEXT_NUMBER[numba[3]]
endif
endif
elseif ti == 2 then
if numba[1] == 1 then
set result = result + TEXT_NUMBER[ ( numba[1] * 10 ) + numba[2] ]
elseif numba[1] >= 1 then
if numba[2] != 0 then
set result = result + TEXT_NUMBER[numba[1] * 10] + line + TEXT_NUMBER[numba[2]]
else
set result = result + TEXT_NUMBER[numba[1] * 10]
endif
elseif numba[1] == 0 then
if numba[2] != 0 then
set result = result + TEXT_NUMBER[numba[2]]
else
set bool[2] = true
endif
endif
elseif ti == 1 then
if numba[1] != 0 then
set result = result + TEXT_NUMBER[numba[1]]
else
set bool[2] = true
endif
endif
if bool[2] == false then
set result = result + TEXT_NUMBER[3001]
endif
endif
return result
endfunction
This is a Work In Progress script and it's far from complete.
Please do not complain about that.
Please do not complain about that.
It also seems to work only on 1.24b
Last edited: