Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric amount to verbal one conversion - how to? 1

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
Say, you need to convert

$123,456.78

to

"One Hundred Twenty Three Thousands Four Hundred Fifty Six dollars and 78/100".

Is there some .NET built-in (or custom-made) function that does that?
Or I'll have to "roll yer own"?
TIA!
 
Good post!
One thing is missing, though: decimals.
Lemme play with this NumberToText() function, and if I manage to upgrade it - I'll post it here.
 
OK, what's there by that link (https://stackoverflow.com/questions/22060540/display-amount-in-words-in-vb-net, thank you again, Andrzejek!) is conversion of the Integer to String.
But I needed dollar (pound/krona/rupee/ruble/hrivnia/dinar/peso/rand/tugrik/yuan/yen/etc.) amount conversion from numeric (or decimal) to string, formatted as it's shown on a paycheck or some other financial documents.
Thus, I put together the function that does exactly that, here it is:
Code:
'============================================================================================================
Function ChkAmount2Text(ByVal tnAmt As Decimal, Optional ByVal tcCurrency As String = "Dollars") As String
'============================================================================================================
' Purpose       : Converts the given amount into a string.
' Description   : Checks the given amount parameter for zero and less than one amounts, if so - formats the string and returns it.
'                        If 1 and greater, calls the NumberToText() to convert the integer part into a string and adds the decimals' string.
' Parameters     : Amount to convert;
'                        Currency name.
' Returns         : Formatted check amount .
' Side effects  : None.
' Notes         : 1. Generic.
'                 2. Complies with .NET Framework ver. 1.1 and higher, .NET ver. Core 1.0 and higher.
'                        3. No parameters' verification, presumed valid.
'                        4. Calls the NumberToText() function to get the integral part.
' Author        : Ilya I. Rabyy
' Revisions     : by Ilya on 2024-12-11 - completed 1st draft.
'============================================================================================================
If tnAmt <= 0 Then
    Return "0 and 00/100 " + tcCurrency
ElseIf Between(tnAmt, 0.00d, 0.99d) Then
    tnAmt = Math.Round(tnAmt, 2)
    Return "0 and " + Strings.Format(Int(tnAmt * 100), "00") + "/100 " + tcCurrency
End If

Dim lsRet As String = "", lsIntPart As String = "", lsDecimals As String = "", lnDecimals As Decimal

lsIntPart = NumberToText(Int(tnAmt))
lnDecimals = tnAmt - Int(tnAmt)
lsDecimals = Strings.Format(lnDecimals*100, "00") & "/100 " & tcCurrency
lsRet = lsIntPart + " and " + lsDecimals

Return lsRet
End Function
'============================================================================================================

"What d'ya think of that?" (Ian Gillan, "Anyone's Daughter", Deep Purple, "Fireball" 1971)
 

Part and Inventory Search

Sponsor

Back
Top