Jul 19, 2000 #1 Senjen Programmer Jul 14, 2000 23 US anyone have any ideas on converting "$132.00" to "One Hundred thirty two and 00 cents"
anyone have any ideas on converting "$132.00" to "One Hundred thirty two and 00 cents"
Jul 19, 2000 1 #2 famousb Programmer Mar 2, 2000 239 US follows is FAQ 3C, courtesy of Jim Conrad. doesn't include the dollar sign, but i'm sure you should be able to incorporate it without too much trouble.<br><br>Function NumberToWords(InputNumber As Double, Optional NeedCents As Boolean = False) As Variant<br><br> Dim varWords As Variant<br> Dim Billions As Double<br> Dim Millions As Double<br> Dim Thousands As Double<br> Dim Hundreds As Double<br> Dim Cents As Integer<br> Dim varNumber As Variant<br> <br> Dim OneBillion As Double<br> <br> If Not IsNumeric(InputNumber) Then<br> NumberToWords = Null<br> Exit Function<br> End If<br> <br> If InputNumber = 0 Then<br> NumberToWords = "Zero "<br> Exit Function<br> End If<br> <br> OneBillion = 1000000000<br><br> Billions = Int(InputNumber / OneBillion)<br> <br> Millions = InputNumber - (Billions * OneBillion)<br> Millions = Int(Millions / 1000000)<br> <br> Thousands = InputNumber - (Billions * OneBillion) - (Millions * 1000000)<br> Thousands = Int(Thousands / 1000)<br> <br> Hundreds = InputNumber - (Billions * OneBillion) - (Millions * 1000000) - (Thousands * 1000)<br> <br> Cents = (InputNumber - Int(InputNumber)) * 100<br> <br> varWords = SmallNumberToWords(Billions) + "Billion, " & _<br> SmallNumberToWords(Millions) + "Million, " & _<br> SmallNumberToWords(Thousands) + "Thousand, " & _<br> SmallNumberToWords(Hundreds)<br> <br> If NeedCents Then<br> varWords = varWords & "And " & IIf(Cents < 10, "0" & Cents, Cents) & "/100"<br> End If<br> <br> NumberToWords = varWords<br> <br>End Function<br><br>Private Function SmallNumberToWords(SmallNumber As Double) As Variant<br><br> Dim Hundreds As Integer<br> Dim Tens As Integer<br> Dim Units As Integer<br> Dim HundredsWords As Variant<br> Dim TensWords As Variant<br> Dim UnitsWords As Variant<br> <br> Hundreds = Int(SmallNumber / 100)<br> Tens = SmallNumber - (Hundreds * 100) ' Part 1 - Get rid of hundreds<br> Tens = Int(Tens / 10) * 10 ' Part 2 - Truncate Units<br> Units = (SmallNumber - (Hundreds * 100)) - Tens<br> <br> If Tens <= 19 Then<br> Tens = Tens + Units<br> Units = 0<br> End If<br> <br> Select Case Hundreds<br> Case 1: HundredsWords = "One Hundred "<br> Case 2: HundredsWords = "Two Hundred "<br> Case 3: HundredsWords = "Three Hundred "<br> Case 4: HundredsWords = "Four Hundred "<br> Case 5: HundredsWords = "Five Hundred "<br> Case 6: HundredsWords = "Six Hundred "<br> Case 7: HundredsWords = "Seven Hundred "<br> Case 8: HundredsWords = "Eight Hundred "<br> Case 9: HundredsWords = "Nine Hundred "<br> Case Else: HundredsWords = Null<br> End Select<br> <br> Select Case Tens<br> Case 1: TensWords = "One "<br> Case 2: TensWords = "Two "<br> Case 3: TensWords = "Three "<br> Case 4: TensWords = "Four "<br> Case 5: TensWords = "Five "<br> Case 6: TensWords = "Six "<br> Case 7: TensWords = "Seven "<br> Case 8: TensWords = "Eight "<br> Case 9: TensWords = "Nine "<br> Case 10: TensWords = "Ten "<br> Case 11: TensWords = "Eleven "<br> Case 12: TensWords = "Twelve "<br> Case 13: TensWords = "Thirteen "<br> Case 14: TensWords = "Fourteen "<br> Case 15: TensWords = "Fifteen "<br> Case 16: TensWords = "Sixteen "<br> Case 17: TensWords = "Seventeen "<br> Case 18: TensWords = "Eighteen "<br> Case 19: TensWords = "Nineteen "<br> Case 20: TensWords = "Twenty "<br> Case 30: TensWords = "Thirty "<br> Case 40: TensWords = "Forty "<br> Case 50: TensWords = "Fifty "<br> Case 60: TensWords = "Sixty "<br> Case 70: TensWords = "Seventy "<br> Case 80: TensWords = "Eighty "<br> Case 90: TensWords = "Ninety "<br> Case Else: TensWords = Null<br> End Select<br> <br> Select Case Units<br> Case 1: UnitsWords = "One "<br> Case 2: UnitsWords = "Two "<br> Case 3: UnitsWords = "Three "<br> Case 4: UnitsWords = "Four "<br> Case 5: UnitsWords = "Five "<br> Case 6: UnitsWords = "Six "<br> Case 7: UnitsWords = "Seven "<br> Case 8: UnitsWords = "Eight "<br> Case 9: UnitsWords = "Nine "<br> Case Else: UnitsWords = Null<br> End Select<br> <br> 'Debug.Print "Hundreds " & Hundreds; HundredsWords<br> 'Debug.Print "Tens " & Tens; TensWords<br> 'Debug.Print "Ones " & Units; UnitsWords<br> <br> SmallNumberToWords = HundredsWords & TensWords & UnitsWords<br> <br>End Function<br><br> <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br> Upvote 0 Downvote
follows is FAQ 3C, courtesy of Jim Conrad. doesn't include the dollar sign, but i'm sure you should be able to incorporate it without too much trouble.<br><br>Function NumberToWords(InputNumber As Double, Optional NeedCents As Boolean = False) As Variant<br><br> Dim varWords As Variant<br> Dim Billions As Double<br> Dim Millions As Double<br> Dim Thousands As Double<br> Dim Hundreds As Double<br> Dim Cents As Integer<br> Dim varNumber As Variant<br> <br> Dim OneBillion As Double<br> <br> If Not IsNumeric(InputNumber) Then<br> NumberToWords = Null<br> Exit Function<br> End If<br> <br> If InputNumber = 0 Then<br> NumberToWords = "Zero "<br> Exit Function<br> End If<br> <br> OneBillion = 1000000000<br><br> Billions = Int(InputNumber / OneBillion)<br> <br> Millions = InputNumber - (Billions * OneBillion)<br> Millions = Int(Millions / 1000000)<br> <br> Thousands = InputNumber - (Billions * OneBillion) - (Millions * 1000000)<br> Thousands = Int(Thousands / 1000)<br> <br> Hundreds = InputNumber - (Billions * OneBillion) - (Millions * 1000000) - (Thousands * 1000)<br> <br> Cents = (InputNumber - Int(InputNumber)) * 100<br> <br> varWords = SmallNumberToWords(Billions) + "Billion, " & _<br> SmallNumberToWords(Millions) + "Million, " & _<br> SmallNumberToWords(Thousands) + "Thousand, " & _<br> SmallNumberToWords(Hundreds)<br> <br> If NeedCents Then<br> varWords = varWords & "And " & IIf(Cents < 10, "0" & Cents, Cents) & "/100"<br> End If<br> <br> NumberToWords = varWords<br> <br>End Function<br><br>Private Function SmallNumberToWords(SmallNumber As Double) As Variant<br><br> Dim Hundreds As Integer<br> Dim Tens As Integer<br> Dim Units As Integer<br> Dim HundredsWords As Variant<br> Dim TensWords As Variant<br> Dim UnitsWords As Variant<br> <br> Hundreds = Int(SmallNumber / 100)<br> Tens = SmallNumber - (Hundreds * 100) ' Part 1 - Get rid of hundreds<br> Tens = Int(Tens / 10) * 10 ' Part 2 - Truncate Units<br> Units = (SmallNumber - (Hundreds * 100)) - Tens<br> <br> If Tens <= 19 Then<br> Tens = Tens + Units<br> Units = 0<br> End If<br> <br> Select Case Hundreds<br> Case 1: HundredsWords = "One Hundred "<br> Case 2: HundredsWords = "Two Hundred "<br> Case 3: HundredsWords = "Three Hundred "<br> Case 4: HundredsWords = "Four Hundred "<br> Case 5: HundredsWords = "Five Hundred "<br> Case 6: HundredsWords = "Six Hundred "<br> Case 7: HundredsWords = "Seven Hundred "<br> Case 8: HundredsWords = "Eight Hundred "<br> Case 9: HundredsWords = "Nine Hundred "<br> Case Else: HundredsWords = Null<br> End Select<br> <br> Select Case Tens<br> Case 1: TensWords = "One "<br> Case 2: TensWords = "Two "<br> Case 3: TensWords = "Three "<br> Case 4: TensWords = "Four "<br> Case 5: TensWords = "Five "<br> Case 6: TensWords = "Six "<br> Case 7: TensWords = "Seven "<br> Case 8: TensWords = "Eight "<br> Case 9: TensWords = "Nine "<br> Case 10: TensWords = "Ten "<br> Case 11: TensWords = "Eleven "<br> Case 12: TensWords = "Twelve "<br> Case 13: TensWords = "Thirteen "<br> Case 14: TensWords = "Fourteen "<br> Case 15: TensWords = "Fifteen "<br> Case 16: TensWords = "Sixteen "<br> Case 17: TensWords = "Seventeen "<br> Case 18: TensWords = "Eighteen "<br> Case 19: TensWords = "Nineteen "<br> Case 20: TensWords = "Twenty "<br> Case 30: TensWords = "Thirty "<br> Case 40: TensWords = "Forty "<br> Case 50: TensWords = "Fifty "<br> Case 60: TensWords = "Sixty "<br> Case 70: TensWords = "Seventy "<br> Case 80: TensWords = "Eighty "<br> Case 90: TensWords = "Ninety "<br> Case Else: TensWords = Null<br> End Select<br> <br> Select Case Units<br> Case 1: UnitsWords = "One "<br> Case 2: UnitsWords = "Two "<br> Case 3: UnitsWords = "Three "<br> Case 4: UnitsWords = "Four "<br> Case 5: UnitsWords = "Five "<br> Case 6: UnitsWords = "Six "<br> Case 7: UnitsWords = "Seven "<br> Case 8: UnitsWords = "Eight "<br> Case 9: UnitsWords = "Nine "<br> Case Else: UnitsWords = Null<br> End Select<br> <br> 'Debug.Print "Hundreds " & Hundreds; HundredsWords<br> 'Debug.Print "Tens " & Tens; TensWords<br> 'Debug.Print "Ones " & Units; UnitsWords<br> <br> SmallNumberToWords = HundredsWords & TensWords & UnitsWords<br> <br>End Function<br><br> <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>