vbscript 将美元金额转换为文本(例如:用于支票)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 将美元金额转换为文本(例如:用于支票)相关的知识,希望对你有一定的参考价值。

   Public Shared RptLiteralsDescription As String
    Public Shared RptLiteralsDiscAmt As String
    Public Shared RptLiteralsDocTranAmt As String
    Public Shared RptLiteralsInvoiceNum As String
    Public Shared RptLiteralsLDate As String
    Public Shared RptLiteralsLNetAmount As String
    Public Shared RptLiteralsLNo As String
    Public Shared RptLiteralsLOrderOf As String
    Public Shared RptLiteralsLPayTo As String

    Dim suffixes As String() = {"Thousand ", "Million ", "Billion ", "Trillion ", "Quadrillion ", "Quintillion ", "Sextillion "}
    Dim units As String() = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine "}
    Dim tens As String() = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "}
    Dim digits As String() = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen"}

    Function ExpandPrice(ByVal Price As Decimal, Optional pSeparator As String = ".") As String
        Dim pPrice As String = Microsoft.VisualBasic.Strings.Format(Price, "##################.00")
        Console.WriteLine(pPrice)		
		
		Dim temp As New System.Text.StringBuilder()
				
        Dim parts As String() = pPrice.Split(pSeparator)
        Dim dollars As String = parts(0)
        Dim cents As String = parts(1)
        If CDbl(dollars) > 1 Then
            temp.Append(ExpandIntegerNumber(dollars) & "Dollars ")
            If CInt(cents) > 0 Then
                temp.Append("And ")
            End If
        ElseIf CDbl(dollars) = 0 Then
            temp.Append(ExpandIntegerNumber(dollars) & "Zero Dollars ")
            If CInt(cents) >= 0 Then
                temp.Append("And ")
            End If
        ElseIf CDbl(dollars) = 1 Then
            temp.Append(ExpandIntegerNumber(dollars) & "Dollar ")
        End If
        If CDbl(cents) > 1 Then
            temp.Append(ExpandIntegerNumber(cents) & "Cents")
        ElseIf CDbl(cents) = 0 Then
            temp.Append(ExpandIntegerNumber(cents) & "Zero Cents ")
        ElseIf CDbl(cents) = 1 Then
            temp.Append(ExpandIntegerNumber(cents) & "Cent ")
        End If
        Return temp.ToString()
    End Function

    Function ExpandIntegerNumber(pNumberStr As String) As String
		Dim temp2 As New System.Text.StringBuilder()
        Dim number As String = Microsoft.VisualBasic.StrDup(3 - Microsoft.VisualBasic.Len(pNumberStr) Mod 3, "0") & pNumberStr
        Dim i As Integer, j As Integer = -1
        Dim numPart As String
        For i = Microsoft.VisualBasic.Len(number) - 2 To 1 Step -3
            numPart = Microsoft.VisualBasic.Mid(number, i, 3)
            If CLng(numPart > 0) Then
                If j > -1 Then
                    temp2.Insert(0, suffixes(j), 1)
                End If
            End If
            temp2.Insert(0, GetNumberUnder1000Str(numPart), 1)
            j += 1
        Next
        Return temp2.ToString()
    End Function

    Function GetNumberUnder1000Str(pNumber As String) As String
        Dim temp1 As New System.Text.StringBuilder()
        If Microsoft.VisualBasic.Len(pNumber) = 3 Then
            If CLng(Microsoft.VisualBasic.Left(pNumber, 1)) > 0 Then
                temp1.Append(GetNumberUnder100Str(Microsoft.VisualBasic.Left(pNumber, 1)) & "Hundred ")
            End If
        End If
        temp1.Append(GetNumberUnder100Str(Microsoft.VisualBasic.Right("0" & pNumber, 2)))
        Return temp1.ToString()
    End Function


    Function GetNumberUnder100Str(pNumber As String) As String
        If pNumber > 19 Then
            Return tens(Microsoft.VisualBasic.Left(pNumber, 1) - 2) & units(Microsoft.VisualBasic.Right(pNumber, 1))
        ElseIf pNumber >= 10 And pNumber <= 19 Then
            Return digits(Microsoft.VisualBasic.Right(pNumber, 1))
        Else
            Return units(Microsoft.VisualBasic.Right(pNumber, 1))
        End If
    End Function

    Public Function SetLabels(p_RptLiteralsDescription As String, p_RptLiteralsDiscAmt As String, p_RptLiteralsDocTranAmt As String, p_RptLiteralsInvoiceNum As String, p_RptLiteralsLDate As String, p_RptLiteralsLNetAmount As String, p_RptLiteralsLNo As String, p_RptLiteralsLOrderOf As String, p_RptLiteralsLPayTo As String) As String
        RptLiteralsDescription = p_RptLiteralsDescription
        RptLiteralsDiscAmt = p_RptLiteralsDiscAmt
        RptLiteralsDocTranAmt = p_RptLiteralsDocTranAmt
        RptLiteralsInvoiceNum = p_RptLiteralsInvoiceNum
        RptLiteralsLDate = p_RptLiteralsLDate
        RptLiteralsLNetAmount = p_RptLiteralsLNetAmount
        RptLiteralsLNo = p_RptLiteralsLNo
        RptLiteralsLOrderOf = p_RptLiteralsLOrderOf
        RptLiteralsLPayTo = p_RptLiteralsLPayTo
        Return ""
    End Function

以上是关于vbscript 将美元金额转换为文本(例如:用于支票)的主要内容,如果未能解决你的问题,请参考以下文章

将图像合并为文本的一部分

如何在带有彩色条的格式表中将数字显示为美元金额

如何在 PHP 中将数字格式化为美元金额

有没有一种方法可以通过DTMF输入美元分值?

Python美元人民币转换不输入提示信息

具有运行总计的 SQL 分区