hi all,
this is my first blog.
this is a simple program for convert
number to words.
usage : words(nnumber)
parameters
nnumber
number you want to convert

return
string
example
?
words(
1000)
returns: thousand only

*----------------------------

proc words
para num
* num="000000010.47"
if num>999999999.99
retu "*--numeric overfloaw--*"
endi
vv=int(num)
cnum = allt(str(vv,9))
cnum = padl(cnum,9,"0")
dec1=abs(num-vv)*100
dec=str(dec1,2)
cnum = cnum+"."+dec
num =cnum


*--crore
a1=subs(num,1,1)
a2=subs(num,2,1)
if a1 = "1"
cror=teen_num(a2)
else
cror=tenthplace(a1)+onethplace(a2)
endi
if !empt(cror)
cror=cror+"crore "
endi
*--lakh
a1=subs(num,3,1)
a2=subs(num,4,1)
if a1 = "1"
lack=teen_num(a2)
else
lack=tenthplace(a1)+onethplace(a2)
endi
if !empt(lack)
lack=lack+"lakh "
endi
*--thousand
a1=subs(num,5,1)
a2=subs(num,6,1)
if a1 = "1"
thoua=teen_num(a2)
else
thoua=tenthplace(a1)+onethplace(a2)
endi
if !empt(thoua)
thoua=thoua+"thousand "
endi
*--hundred
a1=subs(num,7,1)
hundr=onethplace(a1)
if !empt(hundr)
hundr=hundr+"hundred "
endi
*--ten
a1=subs(num,8,1)
a2=subs(num,9,1)
if a1 = "1"
tenth=teen_num(a2)
else
tenth=tenthplace(a1)+onethplace(a2)
endi
if !empt(tenth)
if !empt(hundr)
hundr=hundr+ "and "
endi
tenth=tenth
endi
*--paise
a1=subs(num,11,1)
a2=subs(num,12,1)
if a1 = "1"
paise=teen_num(a2)
else
if a2 = "0"
paise=onethplace(a1)
else
paise=tenthplace(a1)+onethplace(a2)
endi
endi
if !empt(paise)
paise = "and "+paise+"paise "
endi
wor=cror+lack+thoua+hundr+tenth+paise
if !empt(wor)
wor= wor+"only "
else
wor="zero "
endi
retu wor
endproc
func onethplace(no)
cretu=""
do case
case no = "1"
cretu="one "
case no = "2"
cretu="two "
case no = "3"
cretu="three "
case no = "4"
cretu="four "
case no = "5"
cretu="five "
case no = "6"
cretu="six "
case no = "7"
cretu="seven "
case no = "8"
cretu="eight "
case no = "9"
cretu="nine "
endc
retu cretu
endfunc
func tenthplace(no)
cretu=""
do case
case no = "1"
cretu="ten "
case no = "2"
cretu="twenty "
case no = "3"
cretu="thirty "
case no = "4"
cretu="fourty "
case no = "5"
cretu="fifty "
case no = "6"
cretu="sixty "
case no = "7"
cretu="seventy "
case no = "8"
cretu="eighty "
case no = "9"
cretu="ninenty "
endc
retu cretu
endfunc
func teen_num(no)
cretu=""
do case
case no = "0"
cretu="ten "
case no = "1"
cretu="eleven "
case no = "2"
cretu="twelve "
case no = "3"
cretu="thirteen "
case no = "4"
cretu="fourteen "
case no = "5"
cretu="fifteen "
case no = "6"
cretu="sixteen "
case no = "7"
cretu="seventeen "
case no = "8"
cretu="eighteen "
case no = "9"
cretu="ninenteen "
endc
retu cretu
endfunc

 

Leave a Reply

Your email address will not be published. Required fields are marked *