1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
Function LITTERAL(Nombre As Currency, Unite As String)
Dim Mcent(99), McentE, Cent, CentE, i As Integer, x As Integer
Dim dec As Boolean, Chiffre As Currency, Avirg As Currency
If Nombre = 0 Then LITTERAL = "zero": Exit Function
dec = False
Chiffre = Nombre
Nombre = Int(Chiffre)
Avirg = Round(Chiffre - Nombre, 2)
If Avirg <> 0 Then Avirg = Split(Avirg, ",")(1): dec = True
If Unite = "" Then Unite = "et"
For x = 0 To 99
Mcent(x) = x
Next x
McentE = Array("", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neuf", "Dix", "Onze", "Douze", "Treize", "Quatorze", "Quinze", _
"Seize", "Dix Sept", "Dix Huit", "Dix Neuf", "Vingt", "Vingt et Un", "Vingt Deux", "Vingt Trois", "Vingt Quatre", "Vingt Cinq", _
"Vingt Six", "Vingt Sept", "Vingt Huit", "Vingt Neuf", "Trente", "Trente et Un", "Trente Deux", "Trente Trois", "Trente Quatre", "Trente Cinq", _
"Trente Six", "Trente Sept", "Trente Huit", "Trente Neuf", "Quarante", "Quarante et Un", "Quarante Deux", "Quarante Trois", "Quarante Quatre", _
"Quarante Cinq", "Quarante Six", "Quarante Sept", "Quarante Huit", "Quarante Neuf", "Cinquante", "Cinquante et Un", "Cinquante Deux", "Cinquante Trois", _
"Cinquante Quatre", "Cinquante Cinq", "Cinquante Six", "Cinquante Sept", "Cinquante Huit", "Cinquante Neuf", "Soixante", "Soixante et Un", _
"Soixante Deux", "Soixante Trois", "Soixante Quatre", "Soixante Cinq", "Soixante Six", "Soixante Sept", "Soixante Huit", "Soixante Neuf", _
"Soixante dix", "Soixante et Onze", "Soixante Douze", "Soixante Treize", "Soixante Quatorze", "Soixante Quinze", "Soixante Seize", _
"Soixante Dix Sept", "Soixante Dix Huit", "Soixante Dix Neuf", "Quatre Vingt", "Quatre Vingt Un", "Quatre Vingt Deux", "Quatre Vingt Trois", _
"Quatre Vingt Quatre", "Quatre Vingt Cinq", "Quatre Vingt Six", "Quatre Vingt Sept", "Quatre Vingt Huit", "Quatre Vingt Neuf", _
"Quatre Vingt dix", "Quatre Vingt Onze", "Quatre Vingt Douze", "Quatre Vingt Treize", "Quatre Vingt Quatorze", "Quatre Vingt Quinze", "Quatre Vingt Seize", _
"Quatre Vingt Dix Sept", "Quatre Vingt Dix Huit", "Quatre Vingt Dix Neuf")
Cent = Array(100, 200, 300, 400, 500, 600, 700, 800, 900)
CentE = Array("", "Cent", "Deux Cent", "Trois Cent", "Quatre Cent", "Cinq Cent", "Six Cent", "Sept Cent", "Huit Cent", "Neuf Cent")
If Nombre < 100 Then LITTERAL = McentE(Nombre): GoTo decim
If Nombre < 200 Then LITTERAL = "Cent " & McentE(Right(Nombre, 2)): GoTo decim
If Nombre < 1000 Then LITTERAL = Trim(McentE(Left(Nombre, 1)) & " Cent " & McentE(Right(Nombre, 2))): GoTo decim
If Nombre < 2000 Then LITTERAL = Trim("Mille " & CentE(Mid(Nombre, 2, 1)) & " " & McentE(Right(Nombre, 2))): GoTo decim
If Nombre < 10000 Then LITTERAL = Trim(McentE(Left(Nombre, 1)) & " Mille " & CentE(Mid(Nombre, 2, 1)) & " " & McentE(Right(Nombre, 2))): GoTo decim
If Nombre < 100000 Then LITTERAL = Trim(Trim(McentE(Left(Nombre, 2)) & " Mille " & CentE(Mid(Nombre, 3, 1)) & " " & McentE(Right(Nombre, 2)))): GoTo decim
If Nombre < 1000000 Then LITTERAL = Trim(CentE(Left(Nombre, 1)) & " " & McentE(Mid(Nombre, 2, 2)) & " Mille " & CentE(Mid(Nombre, 4, 1))) & " " & McentE(Right(Nombre, 2)): GoTo decim
If Nombre >= 1000000 Then LITTERAL = "Un Million ou +": GoTo decim
'pas prévu plus loin, à vous le boulot
'maintenant les décimales
decim:
If Nombre < 2 Then Unite = Left(Unite, Len(Unite) - 1)
If dec = False Then
LITTERAL = LITTERAL & " " & Unite
Exit Function
Else
'prevu sur 2 décimales
LITTERAL = LITTERAL & " " & Unite & " " & McentE(Avirg)
End If
End Function |
Partager