Articles in this section

How to convert Numbers to Words in Bold Reports

Published:
Updated:

Bold Reports allows you to convert number values to words, which enhances readability and improves the presentation of financial reports. This conversion offers the following benefits:

  • Enhanced readability and comprehension of financial information.
  • Conversion of numeric values into English text for financial and business reporting scenarios.
  • Improved presentation and professionalism in financial reports.

The Code Module in Bold Reports allows you to add custom Visual Basic (VB) code to your report. The following example converts numeric values into English words (Dollars and Cents) and supports values up to trillions. You can customize the currency labels to meet your reporting requirements.

  1. Click the outer grey surface report area and then click the Properties icon to open Report Properties.

    image.png

  2. The custom code option is listed under the Code category, click Code… to open Code Module dialog.

    image.png

  3. In the code tab, type the codes in Visual Basic (VB) language.

    image.png

  4. The following code example demonstrates the custom function that converts the given money value integer to a string.

Public Function SpellNumber(ByVal MyNumber)
   Dim Dollars, Cents, Temp
   Dim DecimalPlace, Count
   Dim Places(5) As String

   Places(1) = ""
   Places(2) = " Thousand "
   Places(3) = " Million "
   Places(4) = " Billion "
   Places(5) = " Trillion "

   MyNumber = Trim(Str(MyNumber))
   DecimalPlace = InStr(MyNumber, ".")

   If DecimalPlace > 0 Then
       Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
       MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
   End If

   Count = 1
   Dollars = ""

   Do While MyNumber <> ""
       Temp = GetHundreds(Right(MyNumber, 3))

       If Temp <> "" Then
           Dollars = Temp & Places(Count) & Dollars
       End If

       If Len(MyNumber) > 3 Then
           MyNumber = Left(MyNumber, Len(MyNumber) - 3)
       Else
           MyNumber = ""
       End If

       Count = Count + 1
   Loop

   Select Case Trim(Dollars)
       Case ""
           Dollars = "No Dollars"
       Case "One"
           Dollars = "One Dollar"
       Case Else
           Dollars = Dollars & " Dollars"
   End Select

   Select Case Trim(Cents)
       Case ""
           Cents = ""
       Case "One"
           Cents = " and One Cent"
       Case Else
           Cents = " and " & Cents & " Cents"
   End Select

   SpellNumber = Dollars & Cents
End Function

Function GetHundreds(ByVal MyNumber)
   Dim Result As String

   If Val(MyNumber) = 0 Then Exit Function

   MyNumber = Right("000" & MyNumber, 3)

   If Mid(MyNumber, 1, 1) <> "0" Then
       Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
   End If

   If Mid(MyNumber, 2, 1) <> "0" Then
       Result = Result & GetTens(Mid(MyNumber, 2))
   Else
       Result = Result & GetDigit(Mid(MyNumber, 3))
   End If

   GetHundreds = Trim(Result)
End Function

Function GetTens(ByVal TensText)
   Dim Result As String

   If Val(Left(TensText, 1)) = 1 Then
       Select Case Val(TensText)
           Case 10 : Result = "Ten"
           Case 11 : Result = "Eleven"
           Case 12 : Result = "Twelve"
           Case 13 : Result = "Thirteen"
           Case 14 : Result = "Fourteen"
           Case 15 : Result = "Fifteen"
           Case 16 : Result = "Sixteen"
           Case 17 : Result = "Seventeen"
           Case 18 : Result = "Eighteen"
           Case 19 : Result = "Nineteen"
       End Select
   Else
       Select Case Val(Left(TensText, 1))
           Case 2 : Result = "Twenty "
           Case 3 : Result = "Thirty "
           Case 4 : Result = "Forty "
           Case 5 : Result = "Fifty "
           Case 6 : Result = "Sixty "
           Case 7 : Result = "Seventy "
           Case 8 : Result = "Eighty "
           Case 9 : Result = "Ninety "
       End Select

       Result = Result & GetDigit(Right(TensText, 1))
   End If

   GetTens = Trim(Result)
End Function

Function GetDigit(ByVal Digit)
   Select Case Val(Digit)
       Case 1 : GetDigit = "One"
       Case 2 : GetDigit = "Two"
       Case 3 : GetDigit = "Three"
       Case 4 : GetDigit = "Four"
       Case 5 : GetDigit = "Five"
       Case 6 : GetDigit = "Six"
       Case 7 : GetDigit = "Seven"
       Case 8 : GetDigit = "Eight"
       Case 9 : GetDigit = "Nine"
       Case Else : GetDigit = ""
   End Select
End Function

This sample converts values into English words using Dollars and Cents. To use another currency, replace the currency labels in the code with the appropriate terms.

  1. Click OK.

  2. Use the following expression to invoke the custom code from a textbox:

    =Code.SpellNumber(Fields!Price.Value)
    

    image.png

Note: Replace Price with the actual field name from your dataset.

  1. Click Preview to verify that the numeric value is displayed as words in the report output.
    image.png
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied