-1

vb.net で 10 進通貨をテキスト金額関数に変換した人はいますか?

例えば。$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 に答える