by compaqt » Sat Apr 06, 2013 9:34 am
*-------------------------------------------------------------------------------*
function fig2wrd( nNum, cCurr, cPaise )
local cNum := i2c( nNum ), cRet := '', cDec := ''
cCurr := iif( cCurr = NIL, 'Rupees', cCurr ) + ' '
cPaise := iif( cPaise = NIL, 'Paise' , cPaise ) + ' '
if '.' $ cNum
cDec := substr( cNum, at( '.', cNum ) + 1 )
endif
nNum := int( nNum )
if nNum > 0
cRet := cCurr
endif
cRet += wrd_Crores( nNum )
if .not. empty( cDec )
cRet := alltrim( cRet )
cRet += ' And ' + cPaise
cRet += wrd_Tens( padr( cDec, 2 ) )
endif
if .not. empty( cRet )
cRet := alltrim( cRet )
cRet += ' Only'
endif
return( cRet )
*-------------------------------------------------------------------------------*
static Function wrd_Unit( nNum, cPost )
local cRet := ''
nNum := iif( valtype( nNum ) = 'C', val( nNum ), nNum )
cPost := iif( cPost = NIL, '', cPost )
do case
case nNum = 1; cRet := 'One'
case nNum = 2; cRet := 'Two'
case nNum = 3; cRet := 'Three'
case nNum = 4; cRet := 'Four'
case nNum = 5; cRet := 'Five'
case nNum = 6; cRet := 'Six'
case nNum = 7; cRet := 'Seven'
case nNum = 8; cRet := 'Eight'
case nNum = 9; cRet := 'Nine'
endcase
return( cRet + iif( empty( cRet ), '', cPost ) )
*-------------------------------------------------------------------------------*
static Function wrd_Tens( nNum, cPost )
local cRet := '', cNum
nNum := iif( valtype( nNum ) = 'C', val( nNum ), nNum )
cPost := iif( cPost = NIL, '', cPost )
do case
case nNum = 10; cRet := 'Ten'
case nNum = 11; cRet := 'Eleven'
case nNum = 12; cRet := 'Twelve'
case nNum = 13; cRet := 'Thirteen'
case nNum = 14; cRet := 'Fourteen'
case nNum = 15; cRet := 'Fifteen'
case nNum = 16; cRet := 'Sixteen'
case nNum = 17; cRet := 'Seventeen'
case nNum = 18; cRet := 'Eighteen'
case nNum = 19; cRet := 'Nineteen'
otherwise
if nNum >= 90; cRet := 'Ninety '
elseif nNum >= 80; cRet := 'Eighty '
elseif nNum >= 70; cRet := 'Seventy '
elseif nNum >= 60; cRet := 'Sixty '
elseif nNum >= 50; cRet := 'Fifty '
elseif nNum >= 40; cRet := 'Forty '
elseif nNum >= 30; cRet := 'Thirty '
elseif nNum >= 20; cRet := 'Twenty '
endif
endcase
if nNum < 10 .or. nNum > 20
cNum := i2c( nNum )
cRet += wrd_Unit( substr( cNum, -1 ) )
endif
return( cRet + iif( empty( cRet ), '', cPost ) )
*-------------------------------------------------------------------------------*
static Function wrd_Hundreds( nNum, cPost )
local cRet := '', cNum
nNum := iif( valtype( nNum ) = 'C', val( nNum ), nNum )
cNum := i2c( nNum )
cPost := iif( cPost = NIL, '', cPost )
if nNum > 99
cNum := substr( cNum, -3, 1 )
cRet := wrd_Unit( cNum, ' Hundred ' )
endif
cNum := i2c( nNum )
cRet += wrd_Tens( substr( cNum, -2 ) )
return( cRet + iif( empty( cRet ), '', cPost ) )
*-------------------------------------------------------------------------------*
static Function wrd_Thousands( nNum )
local cRet := '', cNum, nPos := 0, nChar
cNum := i2c( nNum )
if len( cNum ) >= 5
nPos := 4
nChar := 2
elseif len( cNum ) >= 4
nPos := 3
nChar := 1
endif
if nPos > 0
cNum := substr( cNum, len( cNum ) - nPos, nChar )
cRet := wrd_Tens( cNum, ' Thousand ' )
endif
cNum := i2c( nNum )
cRet += wrd_Hundreds( substr( cNum, -3 ) )
return( cRet )
*-------------------------------------------------------------------------------*
static Function wrd_Lakhs( nNum )
local cRet := '', cNum, nPos := 0, nChar
cNum := i2c( nNum )
if len( cNum ) >= 7
nPos := 6
nChar := 2
elseif len( cNum ) >= 6
nPos := 5
nChar := 1
endif
if nPos > 0
cNum := substr( cNum, len( cNum ) - nPos, nChar )
cRet := wrd_Tens( cNum, ' Lakh ' )
endif
cNum := i2c( nNum )
cRet += wrd_Thousands( substr( cNum, -5 ) )
return( cRet )
*-------------------------------------------------------------------------------*
static Function wrd_Crores( nNum )
local cRet := '', cNum, nPos := 0, nChar
cNum := i2c( nNum )
if len( cNum ) >= 10
nPos := 9
nChar := 3
elseif len( cNum ) >= 9
nPos := 8
nChar := 2
elseif len( cNum ) >= 8
nPos := 7
nChar := 1
endif
if nPos > 0
cNum := substr( cNum, len( cNum ) - nPos, nChar )
if nChar <= 2
cRet := wrd_Tens( cNum, ' Crore ' )
else
cRet := wrd_Hundreds( cNum, ' Crore ' )
endif
endif
cNum := i2c( nNum )
cRet += wrd_Lakhs( substr( cNum, -7 ) )
return( cRet )
*-------------------------------------------------------------------------------*
*-------------------------------------------------------------------------------*