[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Spell.sqc --- Oops!



     Ok, I'm forgetfull.   You found me out.   I said I would attach my
version of Spell.sqc, and here it is....
!  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)


!------------------------------------------------------------------------
!
!  The following was added by Mark W. Salem, City of Pittsburgh to extend
!  this call program's formatting of numbers into a string.   
!  Modified on February 10, 1997
!
!-------------------------------------------------------------------------
   let $str_num = to_char(#num)
   unstring $str_num by '.' into $dummy $remain

   if $remain >= '09'
   let #remain = to_number($remain)

   if #remain > 9
      let #remainder = #remain
   else
   evaluate #remain
   when = 0
        let #remainder = 00
   break
   when = 1
        let #remainder = 10
   break
   when = 2
        let #remainder = 20
   break
   when = 3
        let #remainder = 30
   break
   when = 4
        let #remainder = 40
   break
   when = 5
        let #remainder = 50
   break
   when = 6
        let #remainder = 60
   break
   when = 7
        let #remainder = 70
   break
   when = 8
        let #remainder = 80
   break
   when = 9
        let #remainder = 90
   break
   end-evaluate
   end-if

   let $remain = to_char(#remainder)
   end-if

   if $remain = '' or
      $remain = '0' or
      $remain = '00'
      let $remain = 'XX'
   end-if
   let $leading_stars = '****'
   concat $str with $leading_stars
   let $str2 = upper($leading_stars)
   let $str = translate($str2,' ','-')
   let $str2 = rtrim($str,'-')
   concat ' and ' with $str2
   concat $remain with $str2
   concat '/100 Dollars****' with $str2
   let $str = $str2


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