#include "FiveWin.ch"
FUNCTION MAIN()
LOCAL nNum1 := 12345.67, nNum2 := 1234567.89
MsgStop( Gl_NumToE( nNum1 ) )
MsgStop( Gl_NumToE( nNum2 ) )
RETURN NIL
/***************************************************************/
FUNCTION Gl_NumToE( nNum )
LOCAL cBuf := Gl_NumToL( INT( nNum ) ), cDec
IF EMPTY( cBuf )
cBuf := "Zero"
ENDIF
cDec := RIGHT( STR( nNum - INT( nNum ), 16, 5 ), 5 )
IF RIGHT( cDec, 1 ) == "0"
cDec := LEFT( cDec, 4 )
ENDIF
IF RIGHT( cDec, 1 ) == "0"
cDec := LEFT( cDec, 3 )
ENDIF
IF RIGHT( cDec, 1 ) == "0"
cDec := LEFT( cDec, 2 )
ENDIF
RETURN cBuf + " / " + cDec
FUNCTION Gl_NumToL( nNum )
LOCAL cBuf := "", lNeg := .F., nLen, cStr := ""
cBuf := ALLTRIM( STR( nNum ) )
IF LEFT( cBuf, 1 ) == "-"
cBuf := RIGHT( cBuf, LEN( cBuf ) - 1 )
lNeg := .T.
ENDIF
IF VAL( cBuf ) == 1
Vett1( 1, @cStr )
ELSE
IF ( nLen := LEN( cBuf ) ) < 9
cBuf := SPACE( 9 - nLen ) + cBuf
ENDIF
Tr__num( SUBSTR( cBuf, 1, 3 ), @cStr, 1 )
Tr__num( SUBSTR( cBuf, 4, 3 ), @cStr, 2 )
Tr__num( SUBSTR( cBuf, 7, 3 ), @cStr, 3 )
ENDIF
cStr := UPPER( LEFT( cStr, 1 ) ) + RIGHT( cStr, LEN( cStr ) - 1 )
IF lNeg
cStr := "Meno " + cStr
ENDIF
RETURN cStr
STATIC FUNCTION Tr__num( cStr, cBuf, nType )
LOCAL cTmp, nVal, nNum
cTmp := cStr
IF ( nNum := VAL( cTmp ) ) > 0
IF .NOT. LEFT( cStr, 1 ) == '0' .AND. .NOT. LEFT( cStr, 1 ) == ' '
IF .NOT. LEFT( cStr, 1 ) == '1'
Vett1( ASC( LEFT( cStr, 1 ) ) - 48, @cBuf )
ENDIF
cBuf += "cento"
ENDIF
cTmp := SUBSTR( cStr, 2, 2 )
nVal := VAL( cTmp )
IF nVal > 0
IF nVal < 20
IF nType == 1 .OR. nNum > 1
Vett1( nVal, @cBuf )
ENDIF
ELSE
IF SUBSTR( cStr, 3, 1 ) == '0'
Vett2( SUBSTR( cStr, 2, 1 ), @cbuf )
ELSE
IF SUBSTR( cStr, 3, 1 ) == '1'
Vett2( SUBSTR( cStr, 2, 1 ), @cbuf )
Coll( @cBuf, "uno" )
ELSE
IF SUBSTR( cStr, 3, 1 ) == '8'
Vett2( SUBSTR( cStr, 2, 1 ), @cbuf )
Coll( @cBuf, "otto" )
ELSE
Vett2( SUBSTR( cStr, 2, 1 ), @cbuf )
Vett1( ASC( SUBSTR( cStr, 3, 1 ) ) - 48, @cBuf )
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
IF nType <> 3
IF ( nVal := LEN( cBuf ) ) > 2
IF RIGHT( cBuf, 3 ) == "uno"
cBuf := LEFT( cBuf, nVal - 1 )
ENDIF
ENDIF
IF nNum > 1
cBuf += IIF( nType == 1, "milioni", "mila" )
ELSE
cBuf += IIF( nType == 1, "milione", "mille" )
ENDIF
ENDIF
ENDIF
RETURN NIL
STATIC FUNCTION Vett1( nNum, cCifra )
LOCAL cBuf
DO CASE
CASE nNum == 1
cBuf := "uno"
CASE nNum == 2
cBuf := "due"
CASE nNum == 3
cBuf := "tre"
CASE nNum == 4
cBuf := "quattro"
CASE nNum == 5
cBuf := "cinque"
CASE nNum == 6
cBuf := "sei"
CASE nNum == 7
cBuf := "sette"
CASE nNum == 8
cBuf := "otto"
CASE nNum == 9
cBuf := "nove"
CASE nNum == 10
cBuf := "dieci"
CASE nNum == 11
cBuf := "undici"
CASE nNum == 12
cBuf := "dodici"
CASE nNum == 13
cBuf := "tredici"
CASE nNum == 14
cBuf := "quattordici"
CASE nNum == 15
cBuf := "quindici"
CASE nNum == 16
cBuf := "sedici"
CASE nNum == 17
cBuf := "diciassette"
CASE nNum == 18
cBuf := "diciotto"
CASE nNum == 19
cBuf := "diciannove"
ENDCASE
Coll( @cCifra, cBuf )
RETURN NIL
STATIC FUNCTION Vett2( cCar, cCifra )
LOCAL cBuf
DO CASE
CASE cCar == '2'
cBuf := "venti"
CASE cCar == '3'
cBuf := "trenta"
CASE cCar == '4'
cBuf := "quaranta"
CASE cCar == '5'
cBuf := "cinquanta"
CASE cCar == '6'
cBuf := "sessanta"
CASE cCar == '7'
cBuf := "settanta"
CASE cCar == '8'
cBuf := "ottanta"
CASE cCar == '9'
cBuf := "novanta"
ENDCASE
Coll( @cCifra, cBuf )
RETURN NIL
STATIC FUNCTION Coll( cCifra, cBuf )
LOCAL nLen, cCar1, cCar2
IF ( nLen := LEN( cCifra ) ) > 0
cCar1 := RIGHT( cCifra, 1 )
cCar2 := LEFT( cBuf, 1 )
IF ( cCar1 == 'a' .OR. cCar1 == 'e' .OR. ;
cCar1 == 'i' .OR. cCar1 == 'u' .OR. cCar1 == 'o' ) .AND. ;
( cCar2 == 'a' .OR. cCar2 == 'e' .OR. ;
cCar2 == 'i' .OR. cCar2 == 'u' .OR. cCar2 == 'o' )
cCifra := LEFT( cCifra, nLen - 1 )
endif
ENDIF
cCifra += cBuf
RETURN NIL