将数字转换为科威特第纳尔的单词

时间:2017-03-05 08:34:48

标签: excel currency numeric word currency-formatting

我想将科威特第纳尔的数值转换为Excel中的单词,例如:
120.050科威特第纳尔=一百二十科威特第纳尔和五十菲尔兹 100 KWD =仅限一百科威特第纳尔。

2 个答案:

答案 0 :(得分:0)

这可以使用模运算来完成:

Function NumberToFullProseForm(value As Decimal) As String

    Dim value As Decimal = 120.050

    Dim v100 As Decimal = ( value % 100 ) / 100
    Dim v10  As Decimal = ( value %  10 ) / 10
    Dim v1   As Decimal = value %   1
    Dim v01  As Decimal = ( value * 10 ) % 1
    Dim v001 As Decimal = ( value * 100 ) % 1

    Dim output =
        DigitToText( v100 ) + " Hundred and " + 
        DigitToTens( v10 ) + " and " + 
        DigitToText( v1 ) + " Dinars and" + 
        DigitToText( v01 ) + " Tens" + 
        DigitToText( vv001 ) + " Cents"

    Return output
End Function

Function DigitToText(digit As Char) As String

    If digit = 0 Then Return "Zero"
    If digit = 1 Then Return "One"
    ' etc
End Function

Function DigitToTens(digit As Char) As String
    If digit = 0 Then Return ""
    If digit = 1 Then Return "Ten"
    If digit = 2 Then Return "Twenty"
    ' etc
End Function

根据需要调整。

答案 1 :(得分:0)

  1. 按 Alt + F11 键打开 Microsoft Visual Basic for Application 窗口。

  2. 单击“插入”>“模块”并将 VBA 下面的粘贴到新的“模块”窗口。


Function SpellKD(ByVal MyNumber)
 
 '**** Created by Ariful Islam
 '**** arifulsh.com
 '**** Last updated 02-April-2021
 '**** SpellKD shows KD to precede, and to show "" for 0 Fils)
 '****************' Main Function *'****************
 
Dim Kuwaiti_Dinar, Fils, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Lac "
Place(4) = " Crore "
Place(5) = " Arab " ' String representation of amount
MyNumber = Trim(Str(MyNumber)) ' Position of decimal place 0 if none
DecimalPlace = InStr(MyNumber, ".")
 ' Convert Fils and set MyNumber to Dinar amount
If DecimalPlace > 0 Then
    Fils = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
    If Count = 1 Then Temp = GetHundreds(Right(MyNumber, 3))
    If Count > 1 Then Temp = GetHundreds(Right(MyNumber, 2))
    If Temp <> "" Then Kuwaiti_Dinar = Temp & Place(Count) & Kuwaiti_Dinar
    If Count = 1 And Len(MyNumber) > 3 Then
        MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
        If Count > 1 And Len(MyNumber) > 2 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 2)
        Else
            MyNumber = ""
        End If
    End If
    Count = Count + 1
 Loop
Select Case Kuwaiti_Dinar
Case ""
    KD = ""
Case "One"
    KD = "One Kuwaiti Dinar"
Case Else
     '****************************************************************
     'modified the following two lines to display "KD" to precede
     ' rem'd the first line and added the second line
     '****************************************************************
     'KD = KD & " KD"
    Kuwaiti_Dinar = Kuwaiti_Dinar & " Kuwaiti Dinnar"
     
End Select
Select Case Fils
Case ""
     '****************************************************************
     'modified the following two lines to display nothing for no Fils
     ' rem'd the first line and added the second line
     '****************************************************************
     
     'Fils = " and No Fils"
     '****************************************************************
     'modified the following line to display " Only" for no Fils
     ' rem'd the first line and added the second line
     '****************************************************************
     'Fils = ""
    Fils = " Only"
Case "One"
    Fils = " and One Fils"
Case Else
    Fils = " and " & Fils & "Fils"
     
End Select
SpellKD = Kuwaiti_Dinar & Fils
End Function

'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3) 'Convert the hundreds place
If Mid(MyNumber, 1, 1) <> "0" Then
    Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
 'Convert the tens and ones place
If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & GetTens(Mid(MyNumber, 2))
Else
    Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
'*********************************************
' Converts a number from 10 to 99 into text. *
'*********************************************
Function GetTens(TensText)
Dim Result As String
Result = "" ' null out the temporary function value

If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19
    Select Case Val(TensText)
    Case 10: Result = "Ten"
    Case 11: Result = "Eleven"
    Case 12: Result = "Twelve"
    Case 13: Result = "Thirteen"
    Case 14: Result = "Fourteen"
    Case 15: Result = "Fifteen"
    Case 16: Result = "Sixteen"
    Case 17: Result = "Seventeen"
    Case 18: Result = "Eighteen"
    Case 19: Result = "Nineteen"
    Case Else
    End Select
Else ' If value between 20-99
    Select Case Val(Left(TensText, 1))
    Case 2: Result = "Twenty "
    Case 3: Result = "Thirty "
    Case 4: Result = "Forty "
    Case 5: Result = "Fifty "
    Case 6: Result = "Sixty "
    Case 7: Result = "Seventy "
    Case 8: Result = "Eighty "
    Case 9: Result = "Ninety "
    Case Else
    End Select
    Result = Result & GetDigit _
    (Right(TensText, 1)) 'Retrieve ones place
End If
GetTens = Result
End Function
'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

但它永远无法处理超过 99 个文件。它将只计算前 2 个文件数。

注意:这是我的第一个答案。所以,如果有任何错误,请通知我。 谢谢。