CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Has Anyone had to convert numbers to words in ASP?

Print topic Send  topic

Author Message
charles

Posts: 59
Posted: 10/17/2006, 8:56 PM

Has Anyone had to convert numbers to words in ASP? I need to do this for a very important project.
I got this function on the internet.

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

i then added a label2 to my page.On the label's default value,i inserted the following:num2words(label1.value)
The problem is that th code converts everything as 'zero'.
If anyone has done this before i will really appreciate your input.
Thanks in advance.
View profile  Send private message
Edd


Posts: 547
Posted: 10/17/2006, 10:48 PM

charles,

This is because the value of "label1.value" does not exist or is not available at the time of label2 beforeshow.

Access the source value, example
Dim MoneyVal    
MoneyVal = CCGetParam("NameOfDolValColumn", RecordObjName.DataSource.RecordSet.Fields("NameOfDolValColumn")  
Label2.value = num2words(MoneyVal )  

Hope that helps.
Edd

_________________
Accepting and instigating change are life's challenges.

http://www.syntech.com.au
View profile  Send private message
charlesg
Posted: 10/18/2006, 8:50 AM

Thanks edd.
The source for the moneyval is a grid form where i calculated amount payable after deducting taxes etc
Anyway,i modified your code thus
dim moneyval
moneyval=transactions.totalamount.value
label2.value=num2words(moneyval)

Well there was progress but the results is something like this
12000= twelve two twelve
200=two two two
58000=fifty eight two fifty eight
10000=ten two ten
Any idea what could be wrong?
By the way the data type for label should be text.Right?
Thanks
charles

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.