Solved

# Convert currency to words in Reporting Services

Posted on 2009-02-10
2,692 Views
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?

Thanks,

Susan
0
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

http://www.vbexplorer.com/VBExplorer/tips/src36.asp
http://vbcorner.blogspot.com/2007/10/convert-number-currency-to-word-part-i.html

Hope this helps

Rob

0

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 _
String
' 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) & ", " & _
result

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

' 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 _
String
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)
Else
' 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
=code.numbertostring(100)
will print
one Hundred
I tried this
Sabu Varghese
0

## Featured Post

### Suggested Solutions

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…