Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Convert Number to Words in SSRS 2008

$
0
0
Hi All,

As  in the Title I want To expand a formated  number into Words in ssrs 

for example 

55,188.87 =Fifty Five Thousands One Hundred Eighty-Eight Euro And 78 Cents 

such as  currency is returned from Query named CurrencyCode and the Number named Amount 

this is my Query 
SELECT        VoucherCode, CultureID, ReceiverBankAccount, TypeName, ProgramName, projectName, CurrencyCode, VoucherStatus, ReceiptAmount, TypeID, VoucherID,
                         VoucherDate, ReceiptMethodName, ReceiverBankName, ReceiverOrganizationName, programcode, ProgramDescription, AmountFROM            vw_VoucherWHERE        (CultureID = @CultureID) AND (TypeID = 2) AND (VoucherID = @VoucherID)


I searched the net and I found  a custom Code 
SHARED suffixes ASString() = _
{"Thousand ", "Million ", "Billion ", "Trillion ", _"Quadrillion ", "Quintillion ", "Sextillion "}SHARED units ASString() = _
{"","One ", "Two ", "Three ", "Four ", "Five ", _"Six ", "Seven ", "Eight ", "Nine "}SHARED tens ASString() = _
{"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", _"Seventy ", "Eighty ", "Ninety "}SHARED digits ASString() = _
{"Ten ","Eleven ", "Twelve ", "Thirteen ", "Fourteen ", _"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen"}SHARED expr ASNEW _
System.Text.RegularExpressions.Regex("^-?\d+(\.\d{2})?$", _
System.Text.RegularExpressions.RegexOptions.None)PublicFunction ExpandPrice(Price ASDouble, Optional pSeparator ASString = ".") ASStringDim pPrice AsString
pPrice = FORMAT(Price,"##############.00")Dim temp ASNew System.Text.StringBuilder()IfNot expr.IsMatch(pPrice) Then' temp.Append(pPrice) or whatever you want to do here ElseDim parts ASString() = pPrice.Split(pSeparator)Dim dollars ASString = parts(0)Dim cents ASString = parts(1)IfCDbl(dollars) > 1 Then
 temp.Append(ExpandIntegerNumber(dollars) & "Dollars ")IfCInt(cents) > 0 Then
 temp.Append("And ")EndIfElseIfCDbl(dollars) = 0 Then
 temp.Append(ExpandIntegerNumber(dollars) & "Zero Dollars ")IfCInt(cents) >= 0 Then
 temp.Append("And ")EndIfElseIfCDbl(dollars) = 1 Then

temp.Append(ExpandIntegerNumber(dollars) & "Dollar " )EndIfIfCDbl(cents) > 1 Then

temp.Append(ExpandIntegerNumber(cents) & "Cents")ElseIfCDbl(cents) = 0 Then

temp.Append(ExpandIntegerNumber(cents) & "Zero Cents ")ElseIfCDbl(cents) = 1 Then

temp.Append(ExpandIntegerNumber(cents) & "Cent " )EndIfEndIfRETURN temp.ToString()EndFunctionFunction ExpandIntegerNumber(pNumberStr ASString) ASStringDim temp2 ASNew System.Text.StringBuilder()Dim number ASString = _

StrDup(3 - Len(pNumberStr) Mod 3, "0") & pNumberStrDim i ASInteger, j ASInteger = -1Dim numPart ASStringFor i = Len(number) - 2 To 1 Step -3

numPart = Mid(number, i, 3)

IfClng(numPart > 0) ThenIf j > -1 Then

temp2.Insert(0,suffixes(j),1)

EndIfEndIf

temp2.Insert(0,GetNumberUnder1000Str(numPart),1)

j += 1

NextRETURN temp2.ToString()EndFunctionFunction GetNumberUnder1000Str(pNumber ASString) ASStringDim temp1 ASNew System.Text.StringBuilder()If Len(pNumber) = 3 ThenIfCLng(Left(pNumber, 1)) > 0 Then

temp1.Append(GetNumberUnder100Str(Left(pNumber, 1)) & "Hundred ")EndIfEndIf

temp1.Append(GetNumberUnder100Str(Right("0"& pNumber, 2)))RETURN temp1.ToString()EndFunctionFunction GetNumberUnder100Str(pNumber ASString) ASStringIf pNumber > 19 ThenRETURN tens(Left(pNumber, 1) - 2) & units(Right(pNumber, 1))ElseIF pNumber >= 10 and pNumber <= 19 ThenRETURN digits(Right(pNumber, 1))ElseRETURN units(Right(pNumber, 1))EndIfEndFunction
=Code.ExpandPrice(Fields!Amount.Value,".") 

but  it does not work for me, every time I Preview the Report it said  that there is error in custom  code line 75


Where is the problem !!! 

Viewing all articles
Browse latest Browse all 10045

Trending Articles