CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 STILL TRYING TO CONVERT NUMBER TO WORDS IN ASP

Print topic Send  topic

Author Message
charles

Posts: 59
Posted: 10/29/2006, 11:55 PM

I am still trying to implement a functionality that can convert amounts dispalayed on a page from numbers to words.
This is what i have done so far.
Edd gave me a link to a function on an ASP web site.
I then adjusted this function and pasted it on the page in question.
Below is the function
dim ss
dim ds
dim ts
dim qs
dim a
dim i
dim ii
dim s
dim b

ss = "one,two,three,four,five,six,seven,eight,nine"
ds = "ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen," & _
"seventeen,eighteen,nineteen"
ts = "twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"
qs = ",thousand,million,billion"

Function nnn2words(iNum)

a = split(ss,",")
i = iNum mod 10
if i > 0 then s = a(i-1)
ii = int(iNum mod 100)\10
if ii = 1 then
s = split(ds,",")(i)
elseif ((ii>1) and (ii<10)) then
s = split(ts,",")(ii-2) & " " & s
end if
i = (iNum \ 100) mod 10
if i > 0 then s = a(i-1) & " hundred " & s
nnn2words = s
End Function

Function num2words(iNum)

i = iNum
if i < 0 then b = true: i = i*-1
if i = 0 then
s="zero"
elseif i <= 2147483647 then
a = split(qs,",")
for j = 0 to 3
iii = i mod 1000
i = i \ 1000
if iii > 0 then s = nnn2words(iii) & _
" " & a(j) & " " & s
next
else
s = "out of range value"
end if
if b then s = "negative " & s
num2words = trim(s)
End Function

on the page, i added the following code to the before show event of the label to dispaly the amount in words.

dim moneyval
moneyval=transactions.totalamount.value
label2.value=num2words(moneyval)

Well there was progress but the results is something like this
12000 is being converted as twelve two twelve
200 is being converted as two two two
58000 is being converted as fifty eight two fifty eight
10000=ten two ten etc
Any idea what could be wrong?
regards,
Charles

View profile  Send private message
Edd


Posts: 547
Posted: 10/30/2006, 4:55 AM

charles

Try this code - some of the variables are supposed to be local
  
dim ss  
dim ds  
dim ts  
dim qs  
  
ss = "one,two,three,four,five,six,seven,eight,nine"   
ds = "ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen, seventeen,eighteen,nineteen"   
ts = "twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"   
qs = ",thousand,million,billion"  
  
Function nnn2words(iNum)   
	Dim a  
	Dim i  
	Dim s	  
	Dim ii  
  
    a = split(ss,",")   
    i = iNum mod 10   
    if i > 0 then s = a(i-1)   
    ii = int(iNum mod 100)\10   
    if ii = 1 then    
        s = split(ds,",")(i)   
    elseif ((ii>1) and (ii<10)) then   
        s = split(ts,",")(ii-2) & " " & s   
    end if   
    i = (iNum \ 100) mod 10   
    if i > 0 then s = a(i-1) & " hundred " & s   
    nnn2words = s   
End Function   
   
Function num2words(iNum)   
	Dim i  
	Dim s  
	Dim a  
	Dim j  
	Dim iii  
	Dim b  
  
    i = iNum   
    if i < 0 then b = true: i = i*-1   
    if i = 0 then   
        s="zero"   
    elseif i <= 2147483647 then   
        a = split(qs,",")   
        for j = 0 to 3   
            iii = i mod 1000   
            i = i \ 1000   
            if iii > 0 then s = nnn2words(iii) & _   
                " " & a(j) & " " & s   
        next   
    else   
        s = "out of range value"   
    end if   
    if b then s = "negative " & s   
    num2words = trim(s)   
End Function   

The results are not that spectactular, it is missing AND statements and commas, but it works.

Edd


_________________
Accepting and instigating change are life's challenges.

http://www.syntech.com.au
View profile  Send private message
charles

Posts: 59
Posted: 10/30/2006, 12:27 PM

Thanks Edd.
You are the man!
By the way, is there a way i can add currency to the conversion?
For example ,twelve thousand dollars/naira
Regards,
charles
View profile  Send private message
Edd


Posts: 547
Posted: 10/30/2006, 10:27 PM

Quote :
By the way, is there a way i can add currency to the conversion?
For example ,twelve thousand dollars/naira

Do you mean internationalise the function?

Edd
_________________
Accepting and instigating change are life's challenges.

http://www.syntech.com.au
View profile  Send private message
charles

Posts: 59
Posted: 10/31/2006, 9:00 AM

Edd, i mean adding currency to the amount dispayed.For example, if $12000 is converted to twelve thousand,it should have a currency added e.g twelve thousand could be dispayed as twelve thousand Dollars etc.
Regards,
charles
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.