Files
harbour-core/harbour/contrib/hbnf/ntow.prg
Viktor Szakats 8c77111447 2009-07-11 07:38 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* tests/mathtest.prg
  * tests/testcgi.prg
  * tests/speedold.prg
  * tests/testhtml.prg
  * tests/wvtext.prg
  * tests/testpre.prg
  * tests/testfor.prg
  * doc/en-EN/string.txt
  * doc/en-EN/memvar2.txt
  * source/rtl/gtdos/gtdos.c
  * source/rtl/gtsln/keytrans.c
  * source/rtl/gtsln/mousesln.c
  * source/rtl/gtsln/gtsln.c
  * source/rtl/gtsln/kbsln.c
  * source/rdd/dbfntx/dbfntx1.c
  * source/rdd/dbfnsx/dbfnsx1.c
  * source/compiler/genc.c
  * contrib/gtalleg/ssf.c
  * contrib/hbct/strdiff.c
  * contrib/hbct/tests/csetarge.prg
  * contrib/hbct/dattime2.c
  * contrib/xhb/fparse.c
  * contrib/xhb/ttable.prg
  * contrib/xhb/freadlin.c
  * contrib/xhb/cstruct.prg
  * contrib/hbgt/strasint.c
  * contrib/hbfbird/tests/testapi.c
  * contrib/hbxbp/xbpsle.prg
  * contrib/hbxbp/xbpmenubar.prg
  * contrib/hbxbp/xbpfiledialog.prg
  * contrib/hbxbp/xbpwindow.prg
  * contrib/hbxbp/xbpdialog.prg
  * contrib/hbxbp/xbp3state.prg
  * contrib/hbnf/scancode.prg
  * contrib/hbnf/vidmode.prg
  * contrib/hbnf/vidcur.prg
  * contrib/hbnf/proper.c
  * contrib/hbnf/rand1.prg
  * contrib/hbnf/fttext.c
  * contrib/hbnf/settime.prg
  * contrib/hbnf/page.prg
  * contrib/hbnf/findith.prg
  * contrib/hbnf/at2.prg
  * contrib/hbnf/dispc.c
  * contrib/hbnf/gcd.prg
  * contrib/hbnf/dosver.prg
  * contrib/hbnf/nooccur.prg
  * contrib/hbnf/asum.prg
  * contrib/hbnf/sleep.prg
  * contrib/hbnf/wda.prg
  * contrib/hbnf/any2any.prg
  * contrib/hbnf/setdate.prg
  * contrib/hbnf/amedian.prg
  * contrib/hbnf/blink.prg
  * contrib/hbnf/aredit.prg
  * contrib/hbnf/xbox.prg
  * contrib/hbnf/ftround.prg
  * contrib/hbnf/hex2dec.prg
  * contrib/hbnf/nwuid.prg
  * contrib/hbnf/aemaxlen.prg
  * contrib/hbnf/nwlstat.prg
  * contrib/hbnf/invclr.prg
  * contrib/hbnf/diskfunc.prg
  * contrib/hbnf/scregion.prg
  * contrib/hbnf/d2e.prg
  * contrib/hbnf/anomatch.prg
  * contrib/hbnf/cntryset.prg
  * contrib/hbnf/ntow.prg
  * contrib/hbnf/aeminlen.prg
  * contrib/hbnf/savesets.prg
  * contrib/hbnf/tbwhile.prg
  * contrib/hbnf/calendar.prg
  * contrib/hbnf/e2d.prg
  * contrib/hbnf/sysmem.prg
  * contrib/hbnf/aading.prg
  * contrib/hbnf/pending.prg
  * contrib/gtqtc/tests/demoqtc.prg
  * contrib/gtqtc/gtqtc.cpp
  * contrib/gtwvg/wvgscrlb.prg
  * contrib/gtwvg/wvgclass.prg
  * contrib/gtwvg/wvgax.prg
  * contrib/gtwvg/wvgpaint.prg
  * contrib/gtwvg/wvgdarea.prg
  * contrib/gtwvg/wvgmle.prg
  * contrib/gtwvg/wvglistb.prg
  * contrib/gtwvg/wvggui.c
  * contrib/gtwvg/wvgpushb.prg
  * contrib/gtwvg/wvgsle.prg
  * contrib/gtwvg/tests/demowvg.prg
  * contrib/gtwvg/wincallb.c
  * contrib/gtwvg/wvgmenub.prg
  * contrib/gtwvg/wvgphdlr.prg
  * contrib/gtwvg/wvgcheck.prg
  * contrib/gtwvg/wvgstatb.prg
  * contrib/gtwvg/wvgstatc.prg
  * contrib/gtwvg/wvgcore.c
  * contrib/gtwvg/wvgtabpg.prg
  * contrib/gtwvg/wvg3stat.prg
  * contrib/gtwvg/wvgsink.c
  * contrib/gtwvg/wvgwing.c
  * contrib/hbmisc/hb_f.c
  * contrib/hbmisc/nconvert.prg
  * contrib/hbmisc/doc/en/ht_file.txt
  * contrib/hbvpdf/hbvpdf.prg
  * contrib/hbvpdf/hbvpdft.prg
  * examples/hbdoc/examples/core_es/memvar2.txt
  * examples/hbmake/hbmake.prg
  * examples/hbsqlit2/tests/hbsqlite.prg
  * examples/guestbk/testcgi.prg
  * examples/guestbk/guestbk.prg
  * examples/pe/editorhi.prg
  * examples/terminal/trm_cli.prg
  * examples/terminal/terminal.prg
  * examples/hscript/dir.hs
  * examples/hscript/ugly.hs
    * Minor formatting.
2009-07-11 05:46:08 +00:00

139 lines
3.8 KiB
Plaintext

/*
* $Id$
*/
/*
* File......: ntow.prg
* Author....: Gary Baren
* CIS ID....: 75470,1027
*
* This is an original work by Gary Baren and is hereby placed in the
* public domain.
*
* Modification history:
* ---------------------
*
* Rev 1.1 15 Aug 1991 23:05:54 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.0 09 Jun 1991 00:26:56 GLENN
* Initial revision.
*
*/
/* $DOC$
* $FUNCNAME$
* FT_NTOW()
* $CATEGORY$
* Conversion
* $ONELINER$
* Translate numeric value to words
* $SYNTAX$
* FT_NTOW( <nNumber> ) -> cWords
* $ARGUMENTS$
* <nNumber> An integer to translate
* $RETURNS$
* A text string representing <nNumber>
* $DESCRIPTION$
* Translates numeric input to a text string.
*
* FT_NTOW is intended to be used with integers only. Since I don't
* know what your application will be, I can't assume the type of
* fraction you want returned (ninety nine cents, 99/100, .99, etc).
* If you want the fraction in words, just pass it as an integer.
*
* Do not pass a negative number! Handle negative numbers any way
* you need to in your code. (ie: CR, DB, Negative, Minus, etc.)
*
* Also, numeric 0 is returned as a null string. You will need to
* make a decision how to output it (zero dollars, no dollars, etc).
* $EXAMPLES$
* ? FT_NTOW( 999 ) -> Nine Hundred Ninety Nine
*
* ? FT_NTOW( 1000 ) -> One Thousand
*
* ? FT_NTOW( 23 ) + " Dollars and " + FT_NTOW( 99 ) + " Cents"
* -> Twenty Three Dollars and Ninety Nine Cents
*
* ? FT_NTOW( 23 ) + " Dollars and " + "99/100"
* -> Twenty Three Dollars and 99/100
*
* x := -23.99
* cents := str( (x - int( x )) * 100, 2, 0 ) + "/100"
* x := int( x )
* string := iif( x < 0, "Credit of ", "Debit of " )
* ? string + FT_NTOW( abs(x) ) + " Dollars and " + "99/100"
* -> Credit of Twenty Three Dollars and 99/100
* $END$
*/
static ones := { "", " One", " Two", " Three", " Four", " Five", ;
" Six", " Seven", " Eight", " Nine" ;
}
static teens := { " Ten", " Eleven", " Twelve", ;
" Thirteen", " Fourteen", " Fifteen", ;
" Sixteen", " Seventeen", " Eighteen", ;
" Nineteen" ;
}
static tens := { "", "", " Twenty", " Thirty", " Forty", " Fifty", ;
" Sixty", " Seventy", " Eighty", " Ninety" }
static qualifiers := { "", " Thousand", " Million", " Billion", " Trillion" }
#ifdef FT_TEST
function main( cNum )
return qout( ft_ntow( val( cNum ) ) )
#endif
function ft_ntow(nAmount)
local nTemp, sResult := " ", nQualNo
local nDiv := 10 ^ ( int( sol10(nAmount) / 3 ) * 3 )
nTemp := int(nAmount % nDiv)
nAmount := int(nAmount / nDiv)
nQualNo := int( sol10( nDiv ) / 3 ) + 1
sResult += grp_to_words(nAmount, qualifiers[ nQualNo ] )
if nTemp > (nDiv /= 1000) .and. (nDiv > 1)
sResult += ft_ntow( nTemp, nDiv )
else
sResult += grp_to_words(nTemp, "")
endif
return ltrim(sResult)
static function grp_to_words(nGrp, sQual)
local sResult := "", nTemp
nTemp := int(nGrp % 100)
nGrp := int(nGrp / 100)
sResult += ones[ nGrp + 1 ] + iif( nGrp > 0, " Hundred", "")
do case
case nTemp > 19
sResult += tens[ int( nTemp / 10 ) + 1 ]
sResult += ones[ int( nTemp % 10 ) + 1 ]
case nTemp < 20 .and. nTemp > 9
sResult += teens[ int( nTemp % 10 ) + 1 ]
case nTemp < 10 .and. nTemp > 0
sResult += ones[ int( nTemp) + 1 ]
endcase
return sResult + sQual
static function sol10( nNumber )
local sTemp
sTemp := ltrim( str( int(nNumber), 0) )
return len(sTemp) - 1