2013-10-22 17 views
-1

有誰已經轉換小數貨幣爲文本量函數在vb.net?轉換小數貨幣爲文本大寫金額

例如。 $ 110.25 - >產量:一百一十美元二十五美分。

+1

你有什麼企圖?你嘗試搜索嗎?的 –

+1

可能重複的[在到字數字轉換C#(http://stackoverflow.com/questions/2729752/converting-numbers-in-to-words-c-sharp) –

回答

1

我以前做過一次類似的功能,這是一個很好的一步,讓你開始,你能適應它:

#Region " Money Abbreviation " 

    ' [ Money Abbreviation Function ] 
    ' 
    ' // By Elektro [email protected] 
    ' 
    ' 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