Results 1 to 5 of 5

Thread: Convert currency into words

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    Convert currency into words

    Hello there,

    does anyone knows how to convert a currency eg. 11,258.64 into words.

    pls help. thanks in advance.
    elbimbo

  2. #2
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    if using oracle convert to julian date...
    not sure with query..

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    VB Code:
    1. Converting Numbers to Words
    2. Through popular demand, we have written this function for converting a number into words. Although not fully tested, in theory it will work for numbers up to one billion billion (10^24), which should cater for most people's needs. If you can think of a better way to do this, please send us some feedback.
    3.  
    4. Public Function numtoword(numstr As Variant) As String
    5. ' The best data type to feed in is
    6. ' Decimal, but it is up to you
    7.  
    8. Dim tempstr As String
    9. Dim newstr As String
    10. numstr = CDec(numstr)
    11.  
    12. If numstr = 0 Then
    13.   numtoword = "zero "
    14.   Exit Function
    15. End If
    16.  
    17. If numstr > 10 ^ 24 Then
    18.   numtoword = "Too big"
    19.   Exit Function
    20. End If
    21.  
    22. If numstr >= 10 ^ 12 Then
    23.   newstr = numtoword(Int(numstr / 10 ^ 12))
    24.   numstr = ((numstr / 10 ^ 12) - _
    25.   Int(numstr / 10 ^ 12)) * 10 ^ 12
    26.   If numstr = 0 Then
    27.     tempstr = tempstr & newstr & "billion "
    28.   Else
    29.     tempstr = tempstr & newstr & "billion, "
    30.   End If
    31. End If
    32.  
    33. If numstr >= 10 ^ 6 Then
    34.   newstr = numtoword(Int(numstr / 10 ^ 6))
    35.   numstr = ((numstr / 10 ^ 6) - _
    36.   Int(numstr / 10 ^ 6)) * 10 ^ 6
    37.   If numstr = 0 Then
    38.     tempstr = tempstr & newstr & "million "
    39.   Else
    40.     tempstr = tempstr & newstr & "million, "
    41.   End If
    42. End If
    43.  
    44. If numstr >= 10 ^ 3 Then
    45.   newstr = numtoword(Int(numstr / 10 ^ 3))
    46.   numstr = ((numstr / 10 ^ 3) - _
    47.   Int(numstr / 10 ^ 3)) * 10 ^ 3
    48.   If numstr = 0 Then
    49.     tempstr = tempstr & newstr & "thousand "
    50.   Else
    51.     tempstr = tempstr & newstr & "thousand, "
    52.   End If
    53. End If
    54.  
    55. If numstr >= 10 ^ 2 Then
    56.   newstr = numtoword(Int(numstr / 10 ^ 2))
    57.   numstr = ((numstr / 10 ^ 2) - _
    58.   Int(numstr / 10 ^ 2)) * 10 ^ 2
    59.   If numstr = 0 Then
    60.     tempstr = tempstr & newstr & "hundred "
    61.   Else
    62.     tempstr = tempstr & newstr & "hundred and "
    63.   End If
    64. End If
    65.  
    66. If numstr >= 20 Then
    67.   Select Case Int(numstr / 10)
    68.   Case 2
    69.   tempstr = tempstr & "twenty "
    70.   Case 3
    71.   tempstr = tempstr & "thirty "
    72.   Case 4
    73.   tempstr = tempstr & "forty "
    74.   Case 5
    75.   tempstr = tempstr & "fifty "
    76.   Case 6
    77.   tempstr = tempstr & "sixty "
    78.   Case 7
    79.   tempstr = tempstr & "seventy "
    80.   Case 8
    81.   tempstr = tempstr & "eighty "
    82.   Case 9
    83.   tempstr = tempstr & "ninety "
    84.   End Select
    85.   numstr = ((numstr / 10) - _
    86.   Int(numstr / 10)) * 10
    87. End If
    88.  
    89. If numstr > 0 Then
    90.   Select Case numstr
    91.   Case 1
    92.   tempstr = tempstr & "one "
    93.   Case 2
    94.   tempstr = tempstr & "two "
    95.   Case 3
    96.   tempstr = tempstr & "three "
    97.   Case 4
    98.   tempstr = tempstr & "four "
    99.   Case 5
    100.   tempstr = tempstr & "five "
    101.   Case 6
    102.   tempstr = tempstr & "six "
    103.   Case 7
    104.   tempstr = tempstr & "seven "
    105.   Case 8
    106.   tempstr = tempstr & "eight "
    107.   Case 9
    108.   tempstr = tempstr & "nine "
    109.   Case 10
    110.   tempstr = tempstr & "ten "
    111.   Case 11
    112.   tempstr = tempstr & "eleven "
    113.   Case 12
    114.   tempstr = tempstr & "twelve "
    115.   Case 13
    116.   tempstr = tempstr & "thirteen "
    117.   Case 14
    118.   tempstr = tempstr & "fourteen "
    119.   Case 15
    120.   tempstr = tempstr & "fifteen "
    121.   Case 16
    122.   tempstr = tempstr & "sixteen "
    123.   Case 17
    124.   tempstr = tempstr & "seventeen "
    125.   Case 18
    126.   tempstr = tempstr & "eighteen "
    127.   Case 19
    128.   tempstr = tempstr & "nineteen "
    129.   End Select
    130.   numstr = ((numstr / 10) - Int(numstr / 10)) * 10
    131. End If
    132. numtoword = tempstr
    133. End Function
    134.  
    135. Thanks to an anonymous person from Cheats World for this alternative, shorter function:
    136.  
    137. Dim Number2s(2 To 9) As String
    138. Dim Number1s(1 To 19) As String
    139. Dim Steps(1 To 4) As String
    140.  
    141. Public Function NumToWord(Numstring As Variant) As String
    142. If Steps(1) = "" Then initstrings
    143. Dim Tempstring As String
    144. Dim Newstring As String
    145. Dim What As Double
    146.  
    147. If Numstring = 0 Then
    148.   NumToWord = "zero"
    149.   Exit Function
    150. End If
    151.  
    152. If Numstring > (10 ^ 24) Then _
    153.   NumToWord = "Number is too big"
    154.   Exit Function
    155. End If
    156.  
    157. Counter = 0
    158. Do
    159.   Counter = Counter + 1
    160.   If Counter > 1 Then
    161.     What = 10 ^ (12 \ ((Counter - 1) * 2))
    162.   Else
    163.     What = 10 ^ 12
    164.   End If
    165.  
    166.   If Numstring >= What Then
    167.   Newstring = NumToWord(Fix(Numstring / What))
    168.   Numstring = ((Numstring / What) - Fix(Numstring / What)) * What
    169.   If Numstring = 0 Then
    170.     Tempstring = Tempstring & Newstring & Steps(Counter) & " "
    171.   Else
    172.     If Counter = 4 Then
    173.     Tempstring = Tempstring & Newstring & _
    174.     Steps(Counter) & " and ": GoToSkipit
    175.     Tempstring = Tempstring & Newstring & _
    176.     Steps(Counter) & ", "
    177.     Skipit:
    178.   End If
    179. End If
    180.  
    181. Loop Until Counter = 4
    182.  
    183. If Numstring >= 20 Then _
    184. Tempstring = Tempstring & _
    185. Number2s(Fix(Numstring / 10)) & " "
    186.  
    187. If Numstring >= 10 And Numstring < 20 Then _
    188. Tempstring = Tempstring & Number1s(CInt(Numstring)) _
    189. & " ": GoTo Skip2
    190.  
    191. Numstring = ((Numstring / 10) - Fix(Numstring / 10)) * 10
    192.  
    193. If Numstring > 0 Then Tempstring = Tempstring & _
    194. Number1s(CInt(Numstring)) & " "
    195. Skip2:
    196.  
    197. NumToWord = Tempstring
    198.  
    199. End Function
    200.  
    201. Public Sub initstrings()
    202. Steps(1) = "billion"
    203. Steps(2) = "million"
    204. Steps(3) = "thousand"
    205. Steps(4) = "hundred"
    206. Number1s(1) = "one"
    207. Number1s(2) = "two"
    208. Number1s(3) = "three"
    209. Number1s(4) = "four"
    210. Number1s(5) = "five"
    211. Number1s(6) = "six"
    212. Number1s(7) = "seven"
    213. Number1s(8) = "eight"
    214. Number1s(9) = "nine"
    215. Number1s(10) = "ten"
    216. Number1s(11) = "eleven"
    217. Number1s(12) = "twelve"
    218. Number1s(13) = "thirteen"
    219. Number1s(14) = "fourteen"
    220. Number1s(15) = "fifteen"
    221. Number1s(16) = "sixteen"
    222. Number1s(17) = "seventeen"
    223. Number1s(18) = "eighteen"
    224. Number1s(19) = "nineteen"
    225. Number2s(2) = "twenty"
    226. Number2s(3) = "thirty"
    227. Number2s(4) = "forty"
    228. Number2s(5) = "fifty"
    229. Number2s(6) = "sixty"
    230. Number2s(7) = "seventy"
    231. Number2s(8) = "eighty"
    232. Number2s(9) = "ninety"
    233. End Sub
    Code from www.allapi.net

  4. #4
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    cool amitabh thaks for the code....

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136
    Thanks man....
    elbimbo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width