'***************************************************************************************************************************
'**********************************************************************************
' __ _____ ___ . ___ _____ ___ ___
'|__| /\ | | | | | | / | | | | | | | | |\ |
'| /__\ | |--- | | |/\ | | | | | | | | | \ |
'| / \ | | \ | |___ | \ | |___| |___| |__ |___| | \|
'
'***********************************************************************************
'
'*************************************************
'*MOTEUR DE BASE POUR FONCTION NOMBRE EN LETTRE
'*NEW VERSION :3.1
'*DATE VERSION :04/2019
'*AUTEUR:patricktoulon
'*************************************************
'***************************************************************************************************************************
Function NombreEnLettre(chain As String, Optional decimale As Long = 0) As String
Dim t, dixx&, dix&, cxx&, u&, uL
uL = Array("", "une", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf", "cent ")
Diz = Array("", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "soixante-dix", "quatre-vingt", "quatre-vingt-dix", "cent")
ms = Array("", " decilliard", " decillion", " nonilliard", " nonillion", " octillard", " octillion", " septilliard", " septillion", " sextilliard", " sextillion", " quintilliard ", " Quintillion", " quadrilliard", " quadrillion", " trilliard", " trillion", " Billiard", " billion", " milliard", " million", " mille", "")
x = UBound(ms)
t = Split(chain, ",")
For c = 0 To UBound(t)
chaine = "00" & t(c)
If c = 1 And decimale <> 0 Then chaine = Right("00" & Left(Val(chaine), 2), 3)
Z = 0
For i = Len(chaine) - 2 To 1 Step -3
Z = Z + 1: seg = Mid(chaine, i, 3)
cxx = Left(seg, 1): dixx = Right(seg, 2): dix = Mid(seg, 2, 1): u = Right(seg, 1)
If cxx = 1 Then cxx = 20: cc = "" Else cc = IIf(cxx > 0, "-cents ", "")
If dix = 9 Or dix = 7 And u >= 1 Then dix = dix - 1: u = u + 10
If dixx > 9 And dixx < 20 Then dix = 0: u = u + 10
If dix >= 2 And dix <= 7 And (u = 1 Or u = 11) Then et = " et " Else et = IIf(dix <> 0, IIf(u <> 0, "-", " "), " ")
If Val(seg) = 0 Then ms(UBound(ms) - Z + 1) = ""
If Z = 2 And Val(seg) = 1 Then uL(1) = ""
If c = 0 Then entier = Application.Trim(Application.Trim(uL(cxx) & cc & Diz(dix) & et & uL(u)) & " " & ms(x) & IIf(Val(seg) > 1 And Z > 2, "s", "") & " " & entier)
uL(1) = "un"
If c > 0 Then dec = dec & "," & Application.Trim(Application.Trim(uL(cxx) & cc & Diz(dix) & et & uL(u)))
x = x - 1
Next
Next
NombreEnLettre = Replace(entier & dec, " ", "-")
End Function