-1

有没有人在 vb.net 中将十进制货币转换为文本金额功能?

例如。110.25 美元 -> 产出:110 美元 25 美分。

4

1 回答 1

1

我之前做过一个类似的功能,这是让你开始的一个很好的步骤,你可以调整它:

#Region " Money Abbreviation "

   ' [ Money Abbreviation Function ]
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   '
   ' MsgBox(Money_Abbreviation(1000))           ' Result: 1 K
   ' MsgBox(Money_Abbreviation(1000000))        ' Result: 1 M
   ' MsgBox(Money_Abbreviation(1500000, False)) ' Result: 1,5 M

   Private Function Money_Abbreviation(ByVal Quantity As Object, _
                                       Optional ByVal Rounded As Boolean = True) As String

       Dim Abbreviation As String = String.Empty

       Select Case Quantity.GetType()

           Case GetType(Int16), GetType(Int32), GetType(Int64)
               Quantity = FormatNumber(Quantity, TriState.False)

           Case Else
               Quantity = FormatNumber(Quantity, , TriState.False)

       End Select

       Select Case Quantity.ToString.Count(Function(character As Char) character = Convert.ToChar("."))

           Case 0 : Return String.Format("${0}", Quantity)
           Case 1 : Abbreviation = "k"
           Case 2 : Abbreviation = "M"
           Case 3 : Abbreviation = "B"
           Case 4 : Abbreviation = "Tr."
           Case 5 : Abbreviation = "Quad."
           Case 6 : Abbreviation = "Quint."
           Case 7 : Abbreviation = "Sext."
           Case 8 : Abbreviation = "Sept."
           Case Else
               Return String.Format("${0}", Quantity)

       End Select

       Return IIf(Rounded, _
              String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") + 1)), Abbreviation), _
              String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") - 1)), Abbreviation))

   End Function

#End Region
于 2013-10-22T11:10:30.247 回答