473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Code to Convert Currency into Words.

vivek kushwaha
Hi guys,
I need codes to convert Currency into Words. e.g.
120,500 into "One Lac. Five hundred only."

in asp.net with vb.net 1.1.


Please if anybody know about it. Reply me.

Vivek.
Mar 24 '08 #1
2 3955
dip_developer
648 Expert 512MB
Hi guys,
I need codes to convert Currency into Words. e.g.
120,500 into "One Lac. Five hundred only."

in asp.net with vb.net 1.1.


Please if anybody know about it. Reply me.

Vivek.

I have got a function from a website...call this function like this
Expand|Select|Wrap|Line Numbers
  1.  Dim rs as Integer 
  2. Dim rsWord as String=RupeesToWord(rs)
  3.  
...........................see if it helps...



Expand|Select|Wrap|Line Numbers
  1. Function RupeesToWord(ByVal MyNumber)
  2. Dim Temp
  3. Dim Rupees, Paisa As String
  4. Dim DecimalPlace, iCount
  5. Dim Hundreds, Words As String
  6. Dim place(9) As String
  7. place(0) = " Thousand "
  8. place(2) = " Lakh "
  9. place(4) = " Crore "
  10. place(6) = " Arab "
  11. place(8) = " Kharab "
  12. On Error Resume Next
  13. ' Convert MyNumber to a string, trimming extra spaces.
  14. MyNumber = Trim(Str(MyNumber))
  15. ' Find decimal place.
  16. DecimalPlace = InStr(MyNumber, ".")
  17. ' If we find decimal place...
  18. If DecimalPlace > 0 Then
  19. ' Convert Paisa
  20. Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
  21. Paisa = " and " & ConvertTens(Temp) & " Paisa"
  22. ' Strip off paisa from remainder to convert.
  23. MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
  24. End If
  25. '===============================================================
  26. Dim TM As String ' If MyNumber between Rs.1 To 99 Only.
  27. TM = Right(MyNumber, 2)
  28. If Len(MyNumber) > 0 And Len(MyNumber) <= 2 Then
  29. If Len(TM) = 1 Then
  30. Words = ConvertDigit(TM)
  31. RupeesToWord = "Rupees " & Words & Paisa & " Only"
  32. Exit Function
  33. Else
  34. If Len(TM) = 2 Then
  35. Words = ConvertTens(TM)
  36. RupeesToWord = "Rupees " & Words & Paisa & " Only"
  37. Exit Function
  38. End If
  39. End If
  40. End If
  41. '===============================================================
  42.  
  43. ' Convert last 3 digits of MyNumber to ruppees in word.
  44. Hundreds = ConvertHundreds(Right(MyNumber, 3))
  45. ' Strip off last three digits
  46. MyNumber = Left(MyNumber, Len(MyNumber) - 3)
  47. iCount = 0
  48. Do While MyNumber <> ""
  49. 'Strip last two digits
  50. Temp = Right(MyNumber, 2)
  51. If Len(MyNumber) = 1 Then
  52.  
  53. If Trim(Words) = "Thousand" Or _
  54. Trim(Words) = "Lakh Thousand" Or _
  55. Trim(Words) = "Lakh" Or _
  56. Trim(Words) = "Crore" Or _
  57. Trim(Words) = "Crore Lakh Thousand" Or _
  58. Trim(Words) = "Arab Crore Lakh Thousand" Or _
  59. Trim(Words) = "Arab" Or _
  60. Trim(Words) = "Kharab Arab Crore Lakh Thousand" Or _
  61. Trim(Words) = "Kharab" Then
  62. Words = ConvertDigit(Temp) & place(iCount)
  63. MyNumber = Left(MyNumber, Len(MyNumber) - 1)
  64. Else
  65. Words = ConvertDigit(Temp) & place(iCount) & Words
  66. MyNumber = Left(MyNumber, Len(MyNumber) - 1)
  67. End If
  68. Else
  69. If Trim(Words) = "Thousand" Or _
  70. Trim(Words) = "Lakh Thousand" Or _
  71. Trim(Words) = "Lakh" Or _
  72. Trim(Words) = "Crore" Or _
  73. Trim(Words) = "Crore Lakh Thousand" Or _
  74. Trim(Words) = "Arab Crore Lakh Thousand" Or _
  75. Trim(Words) = "Arab" Then
  76.  
  77. Words = ConvertTens(Temp) & place(iCount)
  78.  
  79. MyNumber = Left(MyNumber, Len(MyNumber) - 2)
  80. Else
  81. Words = ConvertTens(Temp) & place(iCount) & Words
  82. MyNumber = Left(MyNumber, Len(MyNumber) - 2)
  83. End If
  84. End If
  85. iCount = iCount + 2
  86. Loop
  87. RupeesToWord = "Rupees " & Words & Hundreds & Paisa & " Only"
  88. End Function
  89. ' Conversion for hundreds
  90. '*****************************************
  91. Private Function ConvertHundreds(ByVal MyNumber)
  92. Dim Result As String
  93. ' Exit if there is nothing to convert.
  94. If Val(MyNumber) = 0 Then Exit Function
  95. ' Append leading zeros to number.
  96. MyNumber = Right("000" & MyNumber, 3)
  97. ' Do we have a hundreds place digit to convert?
  98. If Left(MyNumber, 1) <> "0" Then
  99. Result = ConvertDigit(Left(MyNumber, 1)) & " Hundreds "
  100. End If
  101. ' Do we have a tens place digit to convert?
  102. If Mid(MyNumber, 2, 1) <> "0" Then
  103. Result = Result & ConvertTens(Mid(MyNumber, 2))
  104. Else
  105. ' If not, then convert the ones place digit.
  106. Result = Result & ConvertDigit(Mid(MyNumber, 3))
  107. End If
  108. ConvertHundreds = Trim(Result)
  109. End Function
  110. ' Conversion for tens
  111. '*****************************************
  112. Private Function ConvertTens(ByVal MyTens)
  113. Dim Result As String
  114. ' Is value between 10 and 19?
  115. If Val(Left(MyTens, 1)) = 1 Then
  116. Select Case Val(MyTens)
  117. Case 10 : Result = "Ten"
  118. Case 11 : Result = "Eleven"
  119. Case 12 : Result = "Twelve"
  120. Case 13 : Result = "Thirteen"
  121. Case 14 : Result = "Fourteen"
  122. Case 15 : Result = "Fifteen"
  123. Case 16 : Result = "Sixteen"
  124. Case 17 : Result = "Seventeen"
  125. Case 18 : Result = "Eighteen"
  126. Case 19 : Result = "Nineteen"
  127. Case Else
  128. End Select
  129. Else
  130. ' .. otherwise it's between 20 and 99.
  131. Select Case Val(Left(MyTens, 1))
  132. Case 2 : Result = "Twenty "
  133. Case 3 : Result = "Thirty "
  134. Case 4 : Result = "Forty "
  135. Case 5 : Result = "Fifty "
  136. Case 6 : Result = "Sixty "
  137. Case 7 : Result = "Seventy "
  138. Case 8 : Result = "Eighty "
  139. Case 9 : Result = "Ninety "
  140. Case Else
  141. End Select
  142. ' Convert ones place digit.
  143. Result = Result & ConvertDigit(Right(MyTens, 1))
  144. End If
  145. ConvertTens = Result
  146. End Function
  147. Private Function ConvertDigit(ByVal MyDigit)
  148. Select Case Val(MyDigit)
  149. Case 1 : ConvertDigit = "One"
  150. Case 2 : ConvertDigit = "Two"
  151. Case 3 : ConvertDigit = "Three"
  152. Case 4 : ConvertDigit = "Four"
  153. Case 5 : ConvertDigit = "Five"
  154. Case 6 : ConvertDigit = "Six"
  155. Case 7 : ConvertDigit = "Seven"
  156. Case 8 : ConvertDigit = "Eight"
  157. Case 9 : ConvertDigit = "Nine"
  158. Case Else : ConvertDigit = ""
  159. End Select
  160. End Function 
Mar 24 '08 #2
Thanx for the CODE.

I really appreciate it. It's working fine.
Mar 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: D | last post by:
Does anyone have a VBA code that converts numbers to Spelled out numbers? Example 100 to One Hundred. I need it for a check writing program and I don't feel like reinventing the wheel. Thanks
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
1
by: Juan | last post by:
Best way to convert back a currency string into a number(int or long)? If I have, for example, $ 15.000,00 what is the best way to make it again an int or long? pls help!, Juan.
0
by: R. John Reed | last post by:
Hi All, I'm am looking to convert a currency string (e.g. "$1,234.56" to a double value). It appears this will work: double val = Convert.ToDouble(Double.Parse­("$123,456.78901",...
2
by: KB | last post by:
Hi guys, In my DataGrid I have a column that displays decimal values as currency ( I set the Data Formatting expression of that column to {0:C}). So the actual string displayed in the grid looks...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
1
by: czi02 | last post by:
Hi there; Is there anybody out there knows how to design a function or data flow on how to convert a numerical currency valu (33,163.33) into words 33Million one hundred sixty three thousand...
7
by: tararreb | last post by:
#include<stdio.h> /*This line is standard input output, # is directive, include is keyword, and stdio.h is header file*/ #include<stdlib.h> /*This line is standard input output, # is directive,...
1
by: jemar19 | last post by:
import java.util.*; public class Kopi { static Scanner console=new Scanner(System.in); public static void main(Stringargs) { String f; double a,z,y,x,w;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.