69-kun videosida ishlatilgan kodlar
Function NumberToWordUZ(ByVal Num As Double) As String
Dim integerPart As Double
Dim decimalPart As Integer
Dim result As String
' Manfiy sonlar
If Num < 0 Then
NumberToWordUZ = "minus " & NumberToWordUZ(Abs(Num))
Exit Function
End If
integerPart = Int(Num)
decimalPart = Round((Num - integerPart) * 100, 0)
result = NumberGroupToWord(integerPart) & " so‘m"
If decimalPart > 0 Then
result = result & " " & NumberGroupToWord(decimalPart) & " tiyin"
End If
NumberToWordUZ = Application. WorksheetFunction. Trim(result)
End Function
Private Function NumberGroupToWord(ByVal Num As Double) As String
Dim ones As Variant
ones = Array("", "bir", "ikki", "uch", "to‘rt", "besh", "olti", "yetti", "sakkiz", "to‘qqiz")
Dim tens As Variant
tens = Array("", "o‘n", "yigirma", "o‘ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to‘qson")
Dim thousands As Variant
thousands = Array("", "ming", "million", "milliard", "trillion")
If Num = 0 Then
NumberGroupToWord = "nol"
Exit Function
End If
Dim result As String
Dim i As Integer
i = 0
Do While Num > 0
Dim part As Integer
part = Num Mod 1000
If part <> 0 Then
result = ConvertHundredsUZ(part) & " " & thousands(i) & " " & result
End If
Num = Int(Num / 1000)
i = i + 1
Loop
NumberGroupToWord = Application. WorksheetFunction. Trim(result)
End Function
Private Function ConvertHundredsUZ(ByVal Num As Integer) As String
Dim ones As Variant
ones = Array("", "bir", "ikki", "uch", "to‘rt", "besh", "olti", "yetti", "sakkiz", "to‘qqiz")
Dim tens As Variant
tens = Array("", "o‘n", "yigirma", "o‘ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to‘qson")
Dim result As String
If Num >= 100 Then
result = ones(Int(Num / 100)) & " yuz "
Num = Num Mod 100
End If
If Num >= 10 Then
result = result & tens(Int(Num / 10)) & " "
Num = Num Mod 10
End If
If Num > 0 Then
result = result & ones(Num)
End If
ConvertHundredsUZ = result
End Function