Bonjour a tous

j'ai proposé il y a un moment de cela, une fonction assez compact qui avais pour but de convertir les nombres en toutes lettres en Français dans les contributions .

après plusieurs tests par divers membres certaines petites coquilles avaent fait leur apparition ,celles ci avait été corrigées

j'ai eu envie de faire la même chose mais en anglais

il faut maintenant la tester dans tout les sens

j'ai un soucis avec l'array des mesures
en effet la traduction des unités( mille,milliard,ect....) me parait bizarre sur ggogle translate si quelqu'un connait la traduction de sur!!
je prends

un exemple de bizarerie milliard se dit billion en anglais sauf que billion est l'unité de mesure supérieure a milliard en Français

maintenant testons avec une formule

exemple

=SI(A2<>0;Nombres_En_Lettres_US(A2;"Dollar");"")
testons en VBA

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
Sub test()
    Debug.Print Nombres_En_Lettres_US(5381236.34, "Dollar")
    Debug.Print Nombres_En_Lettres_US(1, "Dollar")
    Debug.Print Nombres_En_Lettres_US(101, "Dollar")
    Debug.Print Nombres_En_Lettres_US(312)
    Debug.Print Nombres_En_Lettres_US(1536.108)
    Debug.Print Nombres_En_Lettres_US(338.246)
    Debug.Print Nombres_En_Lettres_US(999999, "Dollar")
    Debug.Print Nombres_En_Lettres_US(312.36, "Dollar")
    Debug.Print Nombres_En_Lettres_US(1000000000, "Dollar")
    Debug.Print Nombres_En_Lettres_US(1000000338, "Dollar")
End Sub
et enfin la fonction
j'ai relativement simplifié par rapport a la version française (certaines nuances gramaticales de notre chere langue n'existe pas en anglais). j'ai même pas eu besoins de la recursivité
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Option Explicit
 
Public Function Nombres_En_Lettres_US(Nombre As String, Optional monaie As String = ",")
    Dim Unit1, Unit10, Ms, dec, i#, x#, a#, N1$, N2$, N3$, NinT, Part$, NbL$, tabl, N#, T#, unité$
    Unit1 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Height", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Heighteen", "Nineteen")
    Unit10 = Array("", "Ten", "Twenty", "Thirty", "Forty", "Fifty ", "Sixty", "Seventy", "Eighty", "Ninety", "Hundred")
    Ms = Array("", "quadrillion", "trillion", "Billion", "Million", "Thousand", ""):
    dec = Split(Replace(Nombre, ".", ","), ",")
    If UBound(dec) > 0 Then dec(1) = Right("00" & Round(Val("0." & dec(1)), 2) * 100, 3)
    If monaie = "," And UBound(dec) = 0 Then monaie = ""
    monaie = IIf(monaie <> "," And monaie <> "" And Val(dec(0)) > 1, monaie & "s", monaie)
    For i = 0 To UBound(dec)
        If Len(dec(i)) Mod 3 <> 0 Then dec(i) = Application.Rept("0", 3 - Len(dec(i)) Mod 3) & dec(i)
        For N = 1 To Len(dec(i)) Step 3
            Part = Mid(dec(i), N, 3):
 
            N1 = Val(Mid(Part, 1, 1)): N2 = Mid(Part, 2, 1): N3 = Mid(Part, 3, 1): NinT = Mid(Part, 2, 2)
            If NinT > 10 And NinT < 20 Then N2 = 0: N3 = N3 + 10
            NbL = NbL & Unit1(N1) & IIf(N1 <> 0, " hundred ", "")
            NbL = NbL & Unit10(N2) & IIf(N3 <> 0 And N2 <> 0, "-", IIf(Left(Part, 2) = "10" And N3 = 1, " and ", " "))
            NbL = NbL & Unit1(N3) & " "
            NbL = NbL & Chr(1)
        Next
        If i = 0 Then
            tabl = Split(NbL, Chr(1))
            a = UBound(Ms) - UBound(tabl) + 1
            For T = 0 To UBound(tabl) - 1
                If Trim(tabl(T)) <> "" Then unité = Ms(a + x) Else unité = ""
                tabl(T) = tabl(T) & unité & IIf(unité <> "" And Trim(tabl(T)) <> "One" And tabl(T) <> "", "s", "")
                x = x + 1
            Next
            NbL = Join(tabl, " ") & monaie
            NbL = NbL & IIf(UBound(dec) > 0 And monaie <> ",", " & ", "")
        End If
    Next
    Nombres_En_Lettres_US = Trim(Replace(Replace(NbL, "   ", ""), "  ", " "))
End Function
voila testez et donnez moi les coquilles si il y a
merci a tous ceux qui voudrons bien tester