Convert currency to words in Reporting Services

Posted on 2009-02-10
Last Modified: 2012-05-06
Hello experts!
I need a custom code function for Reporting Services that will convert a currency amount to spelled out words for a report I am generating that will print checks.  The currency amounts are the sum of multiple fees in a group that are detailed in the statement on the top portion of the check.  Does anyone know of a function I can put into Custom Code or a Reporting Services function that will convert the report amount to the words?


Question by:suzygm71478
    LVL 11

    Expert Comment

    Try these sites as they have code which you can use as a custom function in your report. Just add the code to the Code tab of the report properties and call the relevant function by using the expression '=code.function()' replacing function() with the name of your function

    Hope this helps


    LVL 1

    Accepted Solution

    We can use this Codes to create User Defined Function.
    REport Body-Rt Clk-Properties-Codes
    Function NumberToString(ByVal num As Double) As _
            ' Remove any fractional part.
        num = Int(num)

        ' If the number is 0, return zero.
        If num = 0 Then Return "zero"

        Static groups() As String = {"", "thousand", "million", _
            "billion", "trillion", "quadrillion", "?", "??", _
            "???", "????"}
        Dim result As String = ""

        ' Process the groups, smallest first.
        Dim quotient As Double
        Dim remainder As Integer
        Dim group_num As Integer = 0
        Do While num > 0
            ' Get the next group of three digits.
            quotient = Int(num / 1000)
            remainder = CInt(num - quotient * 1000)
            num = quotient

            ' Convert the group into words.
            result = GroupToWords(remainder) & _
                " " & groups(group_num) & ", " & _

            ' Get ready for the next group.
            group_num += 1

        ' Remove the trailing ", ".
        If result.EndsWith(", ") Then
            result = result.Substring(0, result.Length - 2)
        End If
        Return result.Trim()  
    End Function

    Function GroupToWords(ByVal num As Integer) As _
        Static one_to_nineteen() As String = {"zero", "one", _
            "two", "three", "four", "five", "six", "seven", _
            "eight", "nine", "ten", "eleven", "twelve", _
            "thirteen", "fourteen", "fifteen", "sixteen", _
            "seventeen", "eightteen", "nineteen"}
        Static multiples_of_ten() As String = {"twenty", _
            "thirty", "forty", "fifty", "sixty", "seventy", _
            "eighty", "ninety"}

        ' If the number is 0, return an empty string.
        If num = 0 Then Return ""

        ' Handle the hundreds digit.
        Dim digit As Integer
        Dim result As String = ""
        If num > 99 Then
            digit = num \ 100
            num = num Mod 100
            result = one_to_nineteen(digit) & " hundred"
        End If

        ' If num = 0, we have hundreds only.
        If num = 0 Then Return result.Trim()

        ' See if the rest is less than 20.
        If num < 20 Then
            ' Look up the correct name.
            result &= " " & one_to_nineteen(num)
            ' Handle the tens digit.
            digit = num \ 10
            num = num Mod 10
            result &= " " & multiples_of_ten(digit - 2)

            ' Handle the final digit.
            If num > 0 Then
                result &= " " & one_to_nineteen(num)
            End If
        End If

        Return result.Trim()
    End Function

    Call the function
     will print
    one Hundred
    I tried this
    Sabu Varghese

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now