Function NumeroInLettere(Numero)
If Numero = 0 Then Exit Function
Dim Frazione1, Frazione2, Frazione3, Esp As Integer
Dim InLettere As String
Dim Temp As Double
Static Cifra(28) As String
Cifra(1) = ""
Cifra(2) = "uno"
Cifra(3) = "due"
Cifra(4) = "tre"
Cifra(5) = "quattro"
Cifra(6) = "cinque"
Cifra(7) = "sei"
Cifra(8) = "sette"
Cifra(9) = "otto"
Cifra(10) = "nove"
Cifra(11) = "dieci"
Cifra(12) = "undici"
Cifra(13) = "dodici"
Cifra(14) = "tredici"
Cifra(15) = "quattordici"
Cifra(16) = "quindici"
Cifra(17) = "sedici"
Cifra(18) = "diciassette"
Cifra(19) = "diciotto"
Cifra(20) = "diciannove"
Cifra(21) = "venti"
Cifra(22) = "trenta"
Cifra(23) = "quaranta"
Cifra(24) = "cinquanta"
Cifra(25) = "sessanta"
Cifra(26) = "settanta"
Cifra(27) = "ottanta"
Cifra(28) = "novanta"
For Esp = 3 To 0 Step -1
Temp = Numero / 1000 ^ Esp
Frazione1 = Int(Temp)
If Frazione1 > 0 Then
Frazione2 = Frazione1
If Frazione2 > 99 Then
Temp = Frazione2 / 100
Frazione3 = Int(Temp)
Frazione2 = Frazione2 - Frazione3 * 100
If Frazione3 = 1 Then
InLettere = InLettere + "cento"
Else
InLettere = InLettere + Cifra(Frazione3 + 1) + "cento"
End If
End If
If Frazione2 <= 20 Then
InLettere = InLettere + Cifra(Frazione2 + 1)
Else
Temp = Frazione2 / 10
Frazione3 = Int(Temp)
InLettere = InLettere + Cifra(Frazione3 + 19)
Frazione2 = Frazione2 - Frazione3 * 10
If Frazione2 = 1 Or Frazione2 = 8 Then
InLettere = Left(InLettere, Len(InLettere) - 1)
End If
InLettere = InLettere + Cifra(Frazione2 + 1)
End If
Select Case Esp
Case 1
If Frazione1 = 1 Then
InLettere = Left(InLettere, Len(InLettere) - 3) + "mille"
Else
InLettere = InLettere + "mila"
End If
Case 2
If Frazione1 = 1 Then
InLettere = Left(InLettere, Len(InLettere) - 3) + "unmilione"
Else
InLettere = InLettere + "milioni"
End If
Case 3
If Frazione1 = 1 Then
InLettere = "unmiliardo"
Else
InLettere = InLettere + "miliardi"
End If
End Select
Numero = Numero - Frazione1 * 1000 ^ Esp
End If
Next
NumeroInLettere = InLettere
End Function
|