[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Numeric Money Conversion to Words
Mark,
There is an example in chapter 19 of the SQR3 Language Tutorial. The
sample program spell.inc is in the tutorial directory if you have it. If
not, here it is:
John L. Kellogg
SQRiBE Technologies Support Manager
! SPELL.INC 10/23/95
!
! Copyright (C) 1995, 1996 MITI All Worldwide Rights Reserved
!
! Disclaimer
!
! This program is provided as an example and, while it is thought to be
free
! from defect, MITI makes no representations or warranties, either
! expressed or implied, with respect to the adequacy of the program in
regard
! to merchantability or fitness for any particular result. The program
is
! provided "as is" and the entire risk as to quality and performance is
with
! the buyer. In no event shall MITI be liable for special, direct,
! indirect or consequential damages resulting from any defect in this
program.
! Some states do not allow the exclusion or limitations of implied
warranties
! or liability for incidental or consequential damages, in which case
the
! above limitations and exclusions may not apply to you.
!
!***************************************************************************
!
! Modification History:
!
! Date Eng Description
! -------- ---
------------------------------------------------------------
! (_V3.5.3_)
! 10-23-95 LHS (DEV-4039)
! o Incorporate into V3.5 codeline
! (_V3.5.4_)
! 04-03-96 PAB (DEV-4088)
! o Cleaned up the modification history.
! (_V4.0_)
! 06-04-96 AIK (1355)
! o Incorporate into V4.0 codeline.
! (_EOH_)
!***************************************************************************
begin-procedure spell_number(#num,:$str)
let $str = ''
! break the number to it's 3-digit parts
let #trillions = floor(#num / 1000000000000)
let #billions = mod(floor(#num / 1000000000),1000)
let #millions = mod(floor(#num / 1000000),1000)
let #thousands = mod(floor(#num / 1000),1000)
let #ones = mod(floor(#num),1000)
! spell each 3-digit part
do spell_3digit(#trillions,'trillion',$str)
do spell_3digit(#billions,'billion',$str)
do spell_3digit(#millions,'million',$str)
do spell_3digit(#thousands,'thousand',$str)
do spell_3digit(#ones,'',$str)
end-procedure ! spell_number
begin-procedure spell_3digit(#num,$part_name,:$str)
let #hundreds = floor(#num / 100)
let #rest = mod(#num,100)
if #hundreds
do spell_digit(#hundreds,$str)
concat 'hundred ' with $str
end-if
if #rest
do spell_2digit(#rest,$str)
end-if
if #hundreds or #rest
if $part_name != ''
concat $part_name with $str
concat ' ' with $str
end-if
end-if
end-procedure ! spell_3digit
begin-procedure spell_2digit(#num,:$str)
let #tens = floor(#num / 10)
let #ones = mod(#num,10)
if #num < 20 and #num > 9
evaluate #num
when = 10
concat 'ten ' with $str
break
when = 11
concat 'eleven ' with $str
break
when = 12
concat 'twelve ' with $str
break
when = 13
concat 'thirteen ' with $str
break
when = 14
concat 'fourteen ' with $str
break
when = 15
concat 'fifteen ' with $str
break
when = 16
concat 'sixteen ' with $str
break
when = 17
concat 'seventeen ' with $str
break
when = 18
concat 'eighteen ' with $str
break
when = 19
concat 'nineteen ' with $str
break
end-evaluate
else
evaluate #tens
when = 2
concat 'twenty' with $str
break
when = 3
concat 'thirty' with $str
break
when = 4
concat 'forty' with $str
break
when = 5
concat 'fifty' with $str
break
when = 6
concat 'sixty' with $str
break
when = 7
concat 'seventy' with $str
break
when = 8
concat 'eighty' with $str
break
when = 9
concat 'ninety' with $str
break
end-evaluate
if #num > 20
if #ones
concat '-' with $str
else
concat ' ' with $str
end-if
end-if
if #ones
do spell_digit(#ones,$str)
end-if
end-if
end-procedure ! spell_2digit
begin-procedure spell_digit(#num,:$str)
evaluate #num
when = 1
concat 'one ' with $str
break
when = 2
concat 'two ' with $str
break
when = 3
concat 'three ' with $str
break
when = 4
concat 'four ' with $str
break
when = 5
concat 'five ' with $str
break
when = 6
concat 'six ' with $str
break
when = 7
concat 'seven ' with $str
break
when = 8
concat 'eight ' with $str
break
when = 9
concat 'nine ' with $str
break
end-evaluate
end-procedure ! spell_digit
Mark W. Salem wrote:
>
> Help! I am in desperate need of a solution to converting a numeric money
> field into its word equivilent; e.g., $1,652.97 --> One thousand - six
> hundred - fifty - two and 97/100
>
> I am using Oracle on a Unix server with a Window's 95 client...
>
> Any suggestions?