Click here to Skip to main content
14,366,974 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I have developing a report using RDLC file in asp.net.
I need how to change numbers to words in report (rdlc file)
please give some idea and coding for change numbers to words in report...

Eg:1950

  results:one thousand nine hundred fifty rupees



Thanks & regards,
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
   
Sure, a 5.
--SA
Mehdi Gholam 25-Nov-11 8:23am
   
Cheers
Rate this:
Please Sign up or sign in to vote.

Solution 2

hi, dear
i have a solution that i was founded on net few days ago.it works nicely.
Try this in your ssrs.
***************************************************************
SHARED suffixes AS String() = _ 
{"Thousand ", "Million ", "Billion ", "Trillion ", _ 
"Quadrillion ", "Quintillion ", "Sextillion "} 

SHARED units AS String() = _ 
{"","One ", "Two ", "Three ", "Four ", "Five ", _ 
"Six ", "Seven ", "Eight ", "Nine "} 

SHARED tens AS String() = _ 
{"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", _ 
"Seventy ", "Eighty ", "Ninety "} 

SHARED digits AS String() = _ 
{"Ten ","Eleven ", "Twelve ", "Thirteen ", "Fourteen ", _ 
"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen"} 

SHARED expr AS NEW _ 
System.Text.RegularExpressions.Regex("^-?\d+(\.\d{2})?$", _ 
System.Text.RegularExpressions.RegexOptions.None) 

PUBLIC Function ExpandPrice(Price AS Double, _ 
Optional pSeparator AS String = ".") _ 
AS String 
Dim pPrice As String 
pPrice = FORMAT(Price,"##############.00") 

Dim temp AS New System.Text.StringBuilder() 
If Not expr.IsMatch(pPrice) Then 
 temp.Append(pPrice) 
Else 
Dim parts AS String() = pPrice.Split(pSeparator) 
Dim dollars AS String = parts(0) 
Dim cents AS String = parts(1) 
If CDbl(dollars) > 1 Then 
temp.Append(ExpandIntegerNumber(dollars) & "Rupees ") 
If CInt(cents) > 0 Then 
temp.Append("And ") 
End If 
ElseIf CDbl(dollars) = 0 Then 
temp.Append(ExpandIntegerNumber(dollars) & "Zero Rupees") 
If CInt(cents) >= 0 Then 
temp.Append("And ") 
End If 
ElseIf CDbl(dollars) = 1 Then 
temp.Append(ExpandIntegerNumber(dollars) & "Rupees " ) 
End If 

If CDbl(cents) > 1 Then 
temp.Append(ExpandIntegerNumber(cents) & "Paise") 
ElseIf CDbl(cents) = 0 Then 
temp.Append(ExpandIntegerNumber(cents) & "Zero Paise ") 
ElseIf CDbl(cents) = 1 Then 
temp.Append(ExpandIntegerNumber(cents) & "Paise " ) 
End If 
End If 
RETURN temp.ToString() 
End Function 

Function ExpandIntegerNumber(pNumberStr AS String) AS String 
Dim temp2 AS New System.Text.StringBuilder() 
Dim number AS String = _ 
StrDup(3 - Len(pNumberStr) Mod 3, "0") & pNumberStr 
Dim i AS Integer, j AS Integer = -1 
Dim numPart AS String 
For i = Len(number) - 2 To 1 Step -3 
numPart = Mid(number, i, 3) 
If Clng(numPart > 0) Then 
If j > -1 Then 
temp2.Insert(0,suffixes(j),1) 
End If 
End If 
temp2.Insert(0,GetNumberUnder1000Str(numPart),1) 
j += 1 
Next 
RETURN temp2.ToString() 
End Function 

Function GetNumberUnder1000Str(pNumber AS String) AS String 
Dim temp1 AS New System.Text.StringBuilder() 
If Len(pNumber) = 3 Then 
If CLng(Left(pNumber, 1)) > 0 Then 
temp1.Append(GetNumberUnder100Str(Left(pNumber, 1)) & "Hundred ") 
End If 
End If 
temp1.Append(GetNumberUnder100Str(Right("0" & pNumber, 2))) 
RETURN temp1.ToString() 
End Function 

Function GetNumberUnder100Str(pNumber AS String) AS String 
If pNumber > 19 Then 
RETURN tens(Left(pNumber, 1) - 2) & units(Right(pNumber, 1)) 
ElseIF pNumber >= 10 and pNumber <= 19 Then 
RETURN digits(Right(pNumber, 1)) 
Else 
RETURN units(Right(pNumber, 1)) 
End If 
End Function 

*****************************************************************

just copy and paste above into your report code block.
on Report

1. add a table on your report.
2. give a dataset.
3. set the expression on the column of your table where's value you want to convert into word. =Code.ExpandPrice(CDbl(Fields!Placement_Amount.Value)).

setting

to set the code into the report. follow the below step.
1. click on the report menu.
2. click on property.
3. click on code and copy the above whole code and paste


if its helpfull plz rate this.
   
v4
Comments
jayapriya.L 25-Nov-11 7:38am
   
i have one doubt in above given answer..
1. add a table on your report.
2. give a dataset.
3. set the expression on the column of your table where's value you want to convert into word. =Code.ExpandPrice(CDbl(Fields!Placement_Amount.Value)).
I am finsihed above steps
after u given know
where coding is i am given
please tel clearly
S.P.Tiwari 28-Nov-11 5:08am
   
i m not getting you. you want to know where you will write the above code..?

then follow the following steps.1. open your report.

2. now you will see the "Report" option in visualStudio toolbar

3. click on Report menu and then click on Report Properties.

4. the you will get a property window click on "Code" the copy and paste the above code.

its a running example so it should be work.if its not working let me know again then i will send you proper step with images.
Member 1586473 24-Aug-12 11:24am
   
Thanks Its working
Brijesh Joshi 2-Nov-15 7:49am
   
Dear Sir,

I want to convert in Indian Currency. e.g. 12546309.20 One Core Twenty Five Lac Fourty Six Thousand Three Hundred Nine Rupees and Twenty Paise. So please let me know how I will do it.

I am highly Thankful to you.

My Email Id is jollybrijesh@gmail.com

Brijesh Joshi
Rate this:
Please Sign up or sign in to vote.

Solution 4

Check out the following code.
public string GetNumberInWord(int number)
 {
  if (number == 0) return "Zero";
  if (number == -2147483648) return "Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight";
  int[] num = new int[4];
  int first = 0;
  int u, h, t;
  System.Text.StringBuilder sb = new System.Text.StringBuilder();
  if (number < 0)
    {
     sb.Append("Minus ");
     number = -number;
    }
  string[] words0 =  { "", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine " };
string[] words = { "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen " };
string[] words2 = { "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety " };
string[] words3 = { "Thousand ", "Lakh ", "Crore " };
num[0] = number % 1000; // units
num[1] = number / 1000;
num[2] = number / 100000;
num[1] = num[1] – 100 * num[2]; // thousands
num[3] = number / 10000000; // crores
num[2] = num[2] – 100 * num[3]; // lakhs
  for (int i = 3; i > 0; i–)
     {
      if (num[i] != 0)
        {
          first = i;
          break;
        }
     }
  for (int i = first; i >= 0; i–)
    {
      if (num[i] == 0) continue;
      u = num[i] % 10; // ones
      t = num[i] / 10;
      h = num[i] / 100; // hundreds
      t = t – 10 * h; // tens
     if (h > 0) sb.Append(words0[h] + "Hundred ");
     if (u > 0 || t > 0)
       {
       if (h > 0 || i == 0) sb.Append("and ");
       if (t == 0)
       sb.Append(words0[u]);
     else if (t == 1)
       sb.Append(words[u]);
     else
       sb.Append(words2[t - 2] + words0[u]);
       }
    if (i != 0) sb.Append(words3[i - 1]);
   }
  return sb.ToString().TrimEnd();
 }
   
Comments
jayapriya.L 2-Jan-12 1:19am
   
Hi
thanks for ur reply....
I put ur code in cstom code and run the program i got the error ...
please tel step by step how to do this in asp.net 4.0 using C#

thanks,
Rate this:
Please Sign up or sign in to vote.

Solution 5

here is a spanish Version:
Function ExpandPrice(ByVal MyNumber)
Dim Temp
Dim Dollars, Cents
Dim DecimalPlace, Count

Dim Place(9) As String
Place(2) = " mil "
Place(3) = " millones "
Place(4) = " billones "
Place(5) = " trillones "

' Convert MyNumber to a string, trimming extra spaces.
MyNumber = Trim(Str(MyNumber))

' Find decimal place.
DecimalPlace = InStr(MyNumber, ".")

' If we find decimal place...
If DecimalPlace > 0 Then
' Convert cents
Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
Cents = ConvertTens(Temp)

' Strip off cents from remainder to convert.
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If

Count = 1
Do While MyNumber <> ""
' Convert last 3 digits of MyNumber to English dollars.
Temp = ConvertHundreds(Right(MyNumber, 3))
If Val(Right(MyNumber, 3)) = 1 Then
Select Case Count
Case 1: Dollars = "uno " & Dollars
Case 2: Dollars = "mil " & Dollars
Case 3: Dollars = "un millón " & Dollars
Case 4: Dollars = "un billón " & Dollars
Case 5: Dollars = "un trillón " & Dollars
Case Else: Dollars = Dollars
End Select
Else
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
End If

If Len(MyNumber) > 3 Then
' Remove last 3 converted digits from MyNumber.
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop

Dollars = Trim(Dollars)

' Clean up dollars.
If Dollars = "" Then Dollars = "cero"

ExpandPrice = Dollars
End Function

Private Function ConvertHundreds(ByVal MyNumber)
Dim Result As String

' Exit if there is nothing to convert.
If Val(MyNumber) = 0 Then Exit Function

' Append leading zeros to number.
MyNumber = Right("000" & MyNumber, 3)

' Do we have a hundreds place digit to convert?
If Left(MyNumber, 1) <> "0" Then
Select Case Left(MyNumber, 1)
Case 1: Result = "ciento "
Case 2: Result = "doscientos "
Case 3: Result = "trescientos "
Case 4: Result = "cuatrocientos "
Case 5: Result = "quinientos "
Case 6: Result = "seiscientos "
Case 7: Result = "setecientos "
Case 8: Result = "ochocientos "
Case 9: Result = "novecientos "
Case Else
End Select
End If

' Do we have a tens place digit to convert?
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & ConvertTens(Mid(MyNumber, 2))
Else
' If not, then convert the ones place digit.
Result = Result & ConvertDigit(Mid(MyNumber, 3))
End If

' is the number exactly 100? If so, overwrite
If Left(MyNumber, 3) = "100" Then
Result = "cien "
End If

ConvertHundreds = Trim(Result)
End Function

Private Function ConvertTens(ByVal MyTens)
Dim Result As String

' Is value between 10 and 19?
If Val(Left(MyTens, 1)) = 1 Or Val(Left(MyTens, 1)) = 2 Then
Select Case Val(MyTens)
Case 10: Result = "diez"
Case 11: Result = "once"
Case 12: Result = "doce"
Case 13: Result = "trece"
Case 14: Result = "catorce"
Case 15: Result = "quince"
Case 16: Result = "dieciseis"
Case 17: Result = "diecisiete"
Case 18: Result = "dieciocho"
Case 19: Result = "diecinueve"
Case 20: Result = "veinte"
Case 21: Result = "veintiuno"
Case 22: Result = "veintidós"
Case 23: Result = "veintitrés"
Case 24: Result = "veinticuatro"
Case 25: Result = "veinticinco"
Case 26: Result = "veintiseis"
Case 27: Result = "veintisiete"
Case 28: Result = "veintiocho"
Case 29: Result = "veintinueve"
Case Else
End Select
Else
' .. otherwise it's between 20 and 99.
Select Case Val(Left(MyTens, 1))
Case 3: Result = "treinta "
Case 4: Result = "cuarenta "
Case 5: Result = "cincuenta "
Case 6: Result = "sesenta "
Case 7: Result = "setenta "
Case 8: Result = "ochenta "
Case 9: Result = "noventa "
Case Else
End Select

' Convert ones place digit.
Result = Result & IIf(Trim(ConvertDigit(Right(MyTens, 1))) = "", "", "y ") & ConvertDigit(Right(MyTens, 1))
End If

ConvertTens = Result
End Function

Private Function ConvertDigit(ByVal MyDigit)
Select Case Val(MyDigit)
Case 1: ConvertDigit = "uno"
Case 2: ConvertDigit = "dos"
Case 3: ConvertDigit = "tres"
Case 4: ConvertDigit = "cuatro"
Case 5: ConvertDigit = "cinco"
Case 6: ConvertDigit = "seis"
Case 7: ConvertDigit = "siete"
Case 8: ConvertDigit = "ocho"
Case 9: ConvertDigit = "nueve"
Case Else: ConvertDigit = ""
End Select
End Function
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100