Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Numbers to Word function
Message
From
08/04/1998 01:56:09
Fernando España
Alta Tecnologia En Informatica
Guatemala, Guatemala
 
 
To
07/04/1998 10:28:43
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00090146
Message ID:
00090345
Views:
22
Here are Two version of this procedure
it's ready to use with report designer an any program in vfp
English Version:********************
FUNCTION NumToWords(nNumber)
*++
*>>Function to convert numeric to words, eg: 120.12 -> "One Hunred Twenty and 12/100"
*--
#define WORD_LENGTH 9
LOCAL ix, cDecimals, cResult, cBuffer
LOCAL cDigits, cTens, cScale
LOCAL nScale, nInteger, nHundreds, nTens, nDigit

m.cDigits = 'Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen SeventeenEighteen NineTeen '
m.cTens = 'Ten Twenty Thirty Fourty Fifty Sixty Seventy Eighty Ninety '
m.cScale = ' Thousand Million Billion Trillion Millardo'

m.nInteger = INT(m.nNumber)
m.cDecimals = ' and ' + PADL(LTRIM(STR(ROUND(m.nNumber % 1, 2) * 100)), 2, '0') + '/100'
m.cResult = ''
m.ix = 0
DO WHILE m.nInteger > 0
m.nScale = m.nInteger % 1000
m.nInteger = INT(m.nInteger / 1000)

m.nHundreds = INT(m.nScale / 100)
m.nTens = m.nScale % 100
m.cBuffer = ''
IF m.nHundreds > 0
m.cBuffer = TRIM(SUBSTR(m.cDigits, m.nHundreds * WORD_LENGTH + 1, WORD_LENGTH)) + ' Hundred '
ENDIF
DO CASE
CASE m.nTens = 0
* do nothing
CASE m.nTens < 20
m.cBuffer = m.cBuffer + TRIM(SUBSTR(m.cDigits, m.nTens * WORD_LENGTH + 1, WORD_LENGTH))
OTHERWISE
m.nDigit = m.nTens % 10
m.nTens = INT(m.nTens / 10) - 1
m.cBuffer = m.cBuffer + TRIM(SUBSTR(m.cTens, m.nTens * WORD_LENGTH + 1, WORD_LENGTH))
IF m.nDigit > 0
m.cBuffer = m.cBuffer + ' ' + TRIM(SUBSTR(m.cDigits, m.nDigit * WORD_LENGTH + 1, WORD_LENGTH))
ENDIF
ENDCASE
IF m.ix > 0
m.cResult = TRIM(TRIM(m.cBuffer) + ' ' + TRIM(SUBSTR(m.cScale, m.ix * WORD_LENGTH + 1, WORD_LENGTH)) + ' ' + m.cResult)
ELSE
m.cResult = TRIM(m.cBuffer)
ENDIF
m.ix = m.ix + 1
ENDDO
IF EMPTY(m.cResult)
m.cResult = TRIM(LEFT(m.cDigits, WORD_LENGTH)) && Zero
ENDIF
RETURN m.cResult + m.cDecimals
ENDFUNC
*\----------------------------------------------------
** I have an spanish version if you like!
*\--------------------------------------------------
Fernando España
SQL Server Specialist
Previous
Reply
Map
View

Click here to load this message in the networking platform