i borrowed and modified this code from Ozgrid.com

Option Compare Database

Option Explicit

Function SpellNumber(ByVal MyNumber)

 Dim Dollars, Cents, Temp

 Dim DecimalPlace, Count



 ReDim Place(9) As String

 Place(2) = " Thousand "

 Place(3) = " Million "

 Place(4) = " Billion "

 Place(5) = " Trillion "



 ' String representation of amount.

 MyNumber = Trim(Str(MyNumber))



 ' Position of decimal place 0 if none.

 DecimalPlace = InStr(MyNumber, ".")

 ' Convert cents and set MyNumber to dollar amount.

 If DecimalPlace > 0 Then

     Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))

     MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

 End If



 Count = 1

 Do While MyNumber <> ""

     Temp = GetHundreds(Right(MyNumber, 3))

     If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars

     If Len(MyNumber) > 3 Then

         MyNumber = Left(MyNumber, Len(MyNumber) - 3)

     Else

         MyNumber = ""

     End If

     Count = Count + 1

 Loop



 Select Case Dollars

     Case ""

         'Dollars = "No Dollars"

     Case "One"

         'Dollars = "One Dollar"

     Case Else

         'Dollars = Dollars & " Dollars"

 End Select



 Select Case Cents

     Case ""

         'Cents = " and No Cents"

     Case "One"

         'Cents = " and One Cent"

     Case Else

         Cents = " and " & Cents & " hundreds"

 End Select



 SpellNumber = Dollars & Cents

End Function

'*******************************************

' Converts a number from 100-999 into text *

'*******************************************

Function GetHundreds(ByVal MyNumber)

Dim Result As String



If Val(MyNumber) = 0 Then Exit Function

MyNumber = Right("000" & MyNumber, 3)



' Convert the hundreds place.

If Mid(MyNumber, 1, 1) <> "0" Then

    Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "

End If



' Convert the tens and ones place.

If Mid(MyNumber, 2, 1) <> "0" Then

    Result = Result & GetTens(Mid(MyNumber, 2))

Else

    Result = Result & GetDigit(Mid(MyNumber, 3))

End If



GetHundreds = Result

End Function

'*********************************************

' Converts a number from 10 to 99 into text. *

'*********************************************

Function GetTens(TensText)

 Dim Result As String



 Result = ""           ' Null out the temporary function value.

 If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...

     Select Case Val(TensText)

         Case 10: Result = "Ten"

         Case 11: Result = "Eleven"

         Case 12: Result = "Twelve"

         Case 13: Result = "Thirteen"

         Case 14: Result = "Fourteen"

         Case 15: Result = "Fifteen"

         Case 16: Result = "Sixteen"

         Case 17: Result = "Seventeen"

         Case 18: Result = "Eighteen"

         Case 19: Result = "Nineteen"

         Case Else

     End Select

 Else                                 ' If value between 20-99...

     Select Case Val(Left(TensText, 1))

         Case 2: Result = "Twenty "

         Case 3: Result = "Thirty "

         Case 4: Result = "Forty "

         Case 5: Result = "Fifty "

         Case 6: Result = "Sixty "

         Case 7: Result = "Seventy "

         Case 8: Result = "Eighty "

         Case 9: Result = "Ninety "

         Case Else

     End Select

     Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.

 End If

 GetTens = Result

End Function

'*******************************************

' Converts a number from 1 to 9 into text. *

'*******************************************

Function GetDigit(Digit)

Select Case Val(Digit)

    Case 1: GetDigit = "One"

    Case 2: GetDigit = "Two"

    Case 3: GetDigit = "Three"

    Case 4: GetDigit = "Four"

    Case 5: GetDigit = "Five"

    Case 6: GetDigit = "Six"

    Case 7: GetDigit = "Seven"

    Case 8: GetDigit = "Eight"

    Case 9: GetDigit = "Nine"

    Case Else: GetDigit = ""

End Select

End Function

Answer from Duane Hookom on learn.microsoft.com
๐ŸŒ
CalculatorSoup
calculatorsoup.com โ€บ calculators โ€บ conversions โ€บ numberstowords.php
Numbers to Words Converter
Convert numbers to words, numbers to USD currency, and currency to words. Includes how to write a check. Use this converter to translate numbers to words in English.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ number-to-word-converter
Numbers to Words Converter from 0 to nonillion
Numbers to Words Converter is an easy-to-use tool to convert Numbers to Readable Strings.
People also ask

Can I convert decimal numbers?
Yes, decimal numbers are converted into words, including currency formats.
๐ŸŒ
lambdatest.com
lambdatest.com โ€บ home โ€บ free tools โ€บ numbers to words
Numbers to Words Converter Online - Amount in words
How many numbers can I convert at once?
The tool supports one number at a time. For batch processing, additional tools may be required.
๐ŸŒ
lambdatest.com
lambdatest.com โ€บ home โ€บ free tools โ€บ numbers to words
Numbers to Words Converter Online - Amount in words
What kind of numbers can I convert?
You can convert positive and negative integers and decimal numbers. The tool is designed to handle very large numbers up to the limits of standard English representation (e.g., quadrillions).
๐ŸŒ
codeshack.io
codeshack.io โ€บ numbers-to-words-converter
Numbers to Words Converter - Online Tool
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ convert-number-to-words
Program to convert a given number to words - GeeksforGeeks
So, the first key numeric value which is smaller than this number is 100. First, we add the quotient part = 203 / 100 = 2, result = "Two". Next, we append the word for key numeric value which is 100, result = "Two Hundred" . Finally, we append the word for remainder part = 203 % 100 = 3, so the final result is = "Two Hundred Three". ... // C++ program to convert number into words by Mapping Key Numeric Values // with English Words #include <iostream> #include <vector> #include <string> using namespace std; string convertToWordsRec(int n, vector<int> &values, vector<string> &words) { string res
Published ย  November 12, 2024
๐ŸŒ
Excel X
excelx.com โ€บ home โ€บ convert number to words in excel
Convert Number to Words in Excel | Excelx.com
July 27, 2023 - Simply return to your Excel sheet and in any cell, write =NumToWords(CELL). You should replace CELL with the cell number that contains the numeric value you wish to convert. For example, =NumToWords(A1) will convert the number in cell A1 to words.
๐ŸŒ
LambdaTest
lambdatest.com โ€บ home โ€บ free tools โ€บ numbers to words
Numbers to Words Converter Online - Amount in words
Easily convert numbers to words with our free online tool. Ideal for generating check amounts, financial documents, and more.
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ integer-to-english-words
Integer to English Words - LeetCode
Integer to English Words - Convert a non-negative integer num to its English words representation. Example 1: Input: num = 123 Output: "One Hundred Twenty Three" Example 2: Input: num = 12345 Output: "Twelve Thousand Three Hundred Forty Five" ...
๐ŸŒ
Boxentriq
boxentriq.com โ€บ home โ€บ code-breaking โ€บ numbers to letters
Numbers to Letters Converter | Boxentriq
Convert numbers into letters instantly! Just type or paste your numbers, choose language and code type, and see the text appear. Any invalid or-non-convertible numbers are shown as #. Switch to ๐Ÿ”€ Letters to Numbers.
Find elsewhere
Top answer
1 of 4
7

i borrowed and modified this code from Ozgrid.com

Option Compare Database

Option Explicit

Function SpellNumber(ByVal MyNumber)

 Dim Dollars, Cents, Temp

 Dim DecimalPlace, Count



 ReDim Place(9) As String

 Place(2) = " Thousand "

 Place(3) = " Million "

 Place(4) = " Billion "

 Place(5) = " Trillion "



 ' String representation of amount.

 MyNumber = Trim(Str(MyNumber))



 ' Position of decimal place 0 if none.

 DecimalPlace = InStr(MyNumber, ".")

 ' Convert cents and set MyNumber to dollar amount.

 If DecimalPlace > 0 Then

     Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))

     MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

 End If



 Count = 1

 Do While MyNumber <> ""

     Temp = GetHundreds(Right(MyNumber, 3))

     If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars

     If Len(MyNumber) > 3 Then

         MyNumber = Left(MyNumber, Len(MyNumber) - 3)

     Else

         MyNumber = ""

     End If

     Count = Count + 1

 Loop



 Select Case Dollars

     Case ""

         'Dollars = "No Dollars"

     Case "One"

         'Dollars = "One Dollar"

     Case Else

         'Dollars = Dollars & " Dollars"

 End Select



 Select Case Cents

     Case ""

         'Cents = " and No Cents"

     Case "One"

         'Cents = " and One Cent"

     Case Else

         Cents = " and " & Cents & " hundreds"

 End Select



 SpellNumber = Dollars & Cents

End Function

'*******************************************

' Converts a number from 100-999 into text *

'*******************************************

Function GetHundreds(ByVal MyNumber)

Dim Result As String



If Val(MyNumber) = 0 Then Exit Function

MyNumber = Right("000" & MyNumber, 3)



' Convert the hundreds place.

If Mid(MyNumber, 1, 1) <> "0" Then

    Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "

End If



' Convert the tens and ones place.

If Mid(MyNumber, 2, 1) <> "0" Then

    Result = Result & GetTens(Mid(MyNumber, 2))

Else

    Result = Result & GetDigit(Mid(MyNumber, 3))

End If



GetHundreds = Result

End Function

'*********************************************

' Converts a number from 10 to 99 into text. *

'*********************************************

Function GetTens(TensText)

 Dim Result As String



 Result = ""           ' Null out the temporary function value.

 If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...

     Select Case Val(TensText)

         Case 10: Result = "Ten"

         Case 11: Result = "Eleven"

         Case 12: Result = "Twelve"

         Case 13: Result = "Thirteen"

         Case 14: Result = "Fourteen"

         Case 15: Result = "Fifteen"

         Case 16: Result = "Sixteen"

         Case 17: Result = "Seventeen"

         Case 18: Result = "Eighteen"

         Case 19: Result = "Nineteen"

         Case Else

     End Select

 Else                                 ' If value between 20-99...

     Select Case Val(Left(TensText, 1))

         Case 2: Result = "Twenty "

         Case 3: Result = "Thirty "

         Case 4: Result = "Forty "

         Case 5: Result = "Fifty "

         Case 6: Result = "Sixty "

         Case 7: Result = "Seventy "

         Case 8: Result = "Eighty "

         Case 9: Result = "Ninety "

         Case Else

     End Select

     Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.

 End If

 GetTens = Result

End Function

'*******************************************

' Converts a number from 1 to 9 into text. *

'*******************************************

Function GetDigit(Digit)

Select Case Val(Digit)

    Case 1: GetDigit = "One"

    Case 2: GetDigit = "Two"

    Case 3: GetDigit = "Three"

    Case 4: GetDigit = "Four"

    Case 5: GetDigit = "Five"

    Case 6: GetDigit = "Six"

    Case 7: GetDigit = "Seven"

    Case 8: GetDigit = "Eight"

    Case 9: GetDigit = "Nine"

    Case Else: GetDigit = ""

End Select

End Function

2 of 4
3

Why not use the found module and simply remove all references to "DOLLARS" or "CENTS"?

๐ŸŒ
Beautify Code
beautifycode.net โ€บ convert-numbers-to-words
Convert Number To Words - Beautify Code
Convert numbers to words in English. You can use this converter when you need to spell in words the numeric values.
๐ŸŒ
CodeShack
codeshack.io โ€บ numbers-to-words-converter
Numbers to Words Converter - Online Tool
Convert numbers to words online with options for different formats (US, British, Euro, Indian), currency, and case types. Free and easy to use.
๐ŸŒ
SEO Magnifier
seomagnifier.com โ€บ numbers-to-words-converter
Numbers to Words Converter Online [100% Free] | SEO Magnifier
The Numbers to Words converter is a handy tool that lets you create the US English word representation of a number, in a short amount of time. You can use whole number or decimal point number format; the calculator converts them to English for you.
๐ŸŒ
GitHub
github.com โ€บ moul โ€บ number-to-words
GitHub - moul/number-to-words: convert number into words (english, french, italian, roman, spanish, portuguese, belgium, dutch, swedish, polish, russian, iranian, roman, aegean)
$ number-to-words --lang=fr 42 quarante-deux $ number-to-words --lang=fr-be 92 nonante-deux $ number-to-words --lang=it 42 quarantadue $ number-to-words --lang=in 42 forty-two $ number-to-words --lang=es 42 cuarenta y dos $ number-to-words --lang=en 42 forty-two $ number-to-words --lang=dk 42 toogfyrre $ number-to-words --lang=se 42 fyrtio-tvรฅ $ number-to-words --lang=nl 42 tweeenveertig $ number-to-words --lang=pl 42 czterdzieล›ci dwa $ number-to-words --lang=tr 42 kฤฑrk iki $ number-to-words --lang=pt-pt 42 quarenta e dois $ number-to-words --lang=roman 42 XLII $ number-to-words --lang=roman-unicode โ…ฉโ…ฌโ…ก $ number-to-words --lang=aegean 42 ๐„“๐„ˆ $ number-to-words --lang=ir 42 ฺ†ู‡ู„ ูˆ ุฏูˆ $ number-to-words --lang=id 42 empat puluh dua
Starred by 91 users
Forked by 27 users
Languages ย  Go 92.0% | Makefile 7.6%
Top answer
1 of 16
70

Ok, I think it's time for my own implementation in Windows BATCH script (should work on Windows 2000 or later).

Here is the code:

@echo off

set zero_to_nineteen=Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen
set twenty_to_ninety=ignore ignore Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety
set big_numbers=ignore Thousand Million Billion Trillion Quadrillion Quintillion Sextillion Septillion Octillion Nonillion Decillion Undecillion Duodecillion Tredecillion Quattuordecillion Quindecillion Sexdecillion Septendecillion Octodecillion Novemdecillion Vigintillion
rem             10^0   10^3     10^6    10^9    10^12    10^15       10^18       10^21      10^24      10^27     10^30     10^33     10^36       10^39        10^42        10^45             10^48         10^51        10^54           10^57         10^60          10^63

call :parse_numbers %*

exit /B 0

:parse_numbers
    :parse_numbers_loop
        if "$%~1" == "$" goto parse_numbers_end
        call :parse_number %~1
        echo %~1 -^> %parse_number_result%
        shift
        goto parse_numbers_loop
    :parse_numbers_end
    exit /B 0

:parse_number
    call :get_sign %~1
    set number_sign=%get_sign_result%
    call :remove_groups %get_sign_result_number%
    call :trim_leading_zeros %remove_groups_result%
    set number=%trim_leading_zeros_result%
    if "$%number%" == "$0" (
        set parse_number_result=Zero
        exit /B 0
    )
    set counter=0
    set parse_number_result=
    :parse_number_loop
        set last_three=%number:~-3%
        set number=%number:~0,-3%
        call :parse_three %last_three%
        call :get_from %counter% %big_numbers%
        if "$%get_from_result%" == "$" (
            set parse_number_result=* ERR: the number is too big! Even wikipedia doesn't know how it's called!
            exit /B 0
        )
        if not "$%parse_three_result%" == "$Zero" (
            if %counter% == 0 (
                set parse_number_result=%parse_three_result%
            ) else (
                if not "$%parse_number_result%" == "$" (
                    set parse_number_result=%parse_three_result% %get_from_result% %parse_number_result%
                ) else (
                    set parse_number_result=%parse_three_result% %get_from_result%
                )
            )
        )
        set /A counter+=1
        if not "$%number%" == "$" goto parse_number_loop
    if "$%parse_number_result%" == "$" (
        set parse_number_result=Zero
        exit /B 0
    ) else if not "$%number_sign%" == "$" (
        set parse_number_result=%number_sign% %parse_number_result%
    )
    exit /B 0

:parse_three
    call :trim_leading_zeros %~1
    set three=%trim_leading_zeros_result%
    set /A three=%three% %% 1000
    set /A two=%three% %% 100
    call :parse_two %two%
    set parse_three_result=
    set /A digit=%three% / 100
    if not "$%digit%" == "$0" (
        call :get_from %digit% %zero_to_nineteen%
    )
    if not "$%digit%" == "$0" (
        if not "$%get_from_result%" == "$Zero" (
            set parse_three_result=%get_from_result% Hundred
        )
    )
    if "$%parse_two_result%" == "$Zero" (
        if "$%parse_three_result%" == "$" (
            set parse_three_result=Zero
        )
    ) else (
        if "$%parse_three_result%" == "$" (
            set parse_three_result=%parse_two_result%
        ) else (
            set parse_three_result=%parse_three_result% %parse_two_result%
        )
    )
    exit /B 0

:parse_two
    call :trim_leading_zeros %~1
    set two=%trim_leading_zeros_result%
    set /A two=%two% %% 100
    call :get_from %two% %zero_to_nineteen%
    if not "$%get_from_result%" == "$" (
        set parse_two_result=%get_from_result%
        goto parse_two_20_end
    )
    set /A digit=%two% %% 10
    call :get_from %digit% %zero_to_nineteen%
    set parse_two_result=%get_from_result%
    set /A digit=%two% / 10
    call :get_from %digit% %twenty_to_ninety%
    if not "$%parse_two_result%" == "$Zero" (
        set parse_two_result=%get_from_result% %parse_two_result%
    ) else (
        set parse_two_result=%get_from_result%
    )
    goto parse_two_20_end
    :parse_two_20_end
    exit /B 0

:get_from
    call :trim_leading_zeros %~1
    set idx=%trim_leading_zeros_result%
    set /A idx=0+%~1
    shift
    :get_from_loop
        if "$%idx%" == "$0" goto get_from_loop_end
        set /A idx-=1
        shift
        goto get_from_loop
    :get_from_loop_end
    set get_from_result=%~1
    exit /B 0

:trim_leading_zeros
    set str=%~1
    set trim_leading_zeros_result=
    :trim_leading_zeros_loop
        if not "$%str:~0,1%" == "$0" (
            set trim_leading_zeros_result=%trim_leading_zeros_result%%str%
            exit /B 0
        )
        set str=%str:~1%
        if not "$%str%" == "$" goto trim_leading_zeros_loop
    if "$%trim_leading_zeros_result%" == "$" set trim_leading_zeros_result=0
    exit /B 0

:get_sign
    set str=%~1
    set sign=%str:~0,1%
    set get_sign_result=
    if "$%sign%" == "$-" (
        set get_sign_result=Minus
        set get_sign_result_number=%str:~1%
    ) else if "$%sign%" == "$+" (
        set get_sign_result_number=%str:~1%
    ) else (
        set get_sign_result_number=%str%
    )
    exit /B 0

:remove_groups
    set str=%~1
    set remove_groups_result=%str:'=%
    exit /B 0

This is the test script I used:

@echo off
rem 10^x:x= 66  63  60  57  54  51  48  45  42  39  36  33  30  27  24  21  18  15  12   9   6   3   0
call number                                                                                          0
call number                                                                                          2
call number                                                                                        -17
call number                                                                                         30
call number                                                                                         48
call number                                                                                       -256
call number                                                                                        500
call number                                                                                        874
call number                                                                                      1'024
call number                                                                                    -17'001
call number                                                                                    999'999
call number                                                                                  1'048'576
call number                                                                         -1'000'001'000'000
call number                                                                    912'345'014'587'957'003
call number                                                       -999'912'345'014'587'124'337'999'999
call number                                        111'222'333'444'555'666'777'888'999'000'000'000'001
call number                               -912'345'014'587'912'345'014'587'124'912'345'014'587'124'337
call number    999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999
call number  1'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000
rem 10^x:x= 66  63  60  57  54  51  48  45  42  39  36  33  30  27  24  21  18  15  12   9   6   3   0

And this is the output I got from my test script:

0 -> Zero
2 -> Two
-17 -> Minus Seventeen
30 -> Thirty
48 -> Forty Eight
-256 -> Minus Two Hundred Fifty Six
500 -> Five Hundred
874 -> Eight Hundred Seventy Four
1'024 -> One Thousand Twenty Four
-17'001 -> Minus Seventeen Thousand One
999'999 -> Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
1'048'576 -> One Million Forty Eight Thousand Five Hundred Seventy Six
-1'000'001'000'000 -> Minus One Trillion One Million
912'345'014'587'957'003 -> Nine Hundred Twelve Quadrillion Three Hundred Forty Five Trillion Fourteen Billion Five Hundred Eighty Seven Million Nine Hundred Fifty Seven Thousand Three
-999'912'345'014'587'124'337'999'999 -> Minus Nine Hundred Ninety Nine Septillion Nine Hundred Twelve Sextillion Three Hundred Forty Five Quintillion Fourteen Quadrillion Five Hundred Eighty Seven Trillion One Hundred Twenty Four Billion Three Hundred Thirty Seven Million Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
111'222'333'444'555'666'777'888'999'000'000'000'001 -> One Hundred Eleven Undecillion Two Hundred Twenty Two Decillion Three Hundred Thirty Three Nonillion Four Hundred Forty Four Octillion Five Hundred Fifty Five Septillion Six Hundred Sixty Six Sextillion Seven Hundred Seventy Seven Quintillion Eight Hundred Eighty Eight Quadrillion Nine Hundred Ninety Nine Trillion One
-912'345'014'587'912'345'014'587'124'912'345'014'587'124'337 -> Minus Nine Hundred Twelve Tredecillion Three Hundred Forty Five Duodecillion Fourteen Undecillion Five Hundred Eighty Seven Decillion Nine Hundred Twelve Nonillion Three Hundred Forty Five Octillion Fourteen Septillion Five Hundred Eighty Seven Sextillion One Hundred Twenty Four Quintillion Nine Hundred Twelve Quadrillion Three Hundred Forty Five Trillion Fourteen Billion Five Hundred Eighty Seven Million One Hundred Twenty Four Thousand Three Hundred Thirty Seven
999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999 -> Nine Hundred Ninety Nine Vigintillion Nine Hundred Ninety Nine Novemdecillion Nine Hundred Ninety Nine Octodecillion Nine Hundred Ninety Nine Septendecillion Nine Hundred Ninety Nine Sexdecillion Nine Hundred Ninety Nine Quindecillion Nine Hundred Ninety Nine Quattuordecillion Nine Hundred Ninety Nine Tredecillion Nine Hundred Ninety Nine Duodecillion Nine Hundred Ninety Nine Undecillion Nine Hundred Ninety Nine Decillion Nine Hundred Ninety Nine Nonillion Nine Hundred Ninety Nine Octillion Nine Hundred Ninety Nine Septillion Nine Hundred Ninety Nine Sextillion Nine Hundred Ninety Nine Quintillion Nine Hundred Ninety Nine Quadrillion Nine Hundred Ninety Nine Trillion Nine Hundred Ninety Nine Billion Nine Hundred Ninety Nine Million Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
1'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000 -> * ERR: the number is too big! Even wikipedia doesn't know how it's called!

If I could find some more names of large numbers, the script would support even bigger numbers. Currently, though, the script will work with all numbers from -(10^66-1) to (10^66-1).

I have to mention, that I had a lot of fun solving this in BATCH. :)

2 of 16
44

C# - 30 lines incl. method declaration and { }s:

Takes into account all the previously aforementioned commas, ands and hyphens. I've only included up to octillion because decimal.MaxValue is only in the octillions. For bigger integers you would need to add corresponding items to the thou[] array and perhaps pass the number in as a string, modifying the line to extract the block by using the last 3 chars instead of using modulo as I have here.

    static string wordify(decimal v)
    {
        if (v == 0) return "zero";
        var units = " one two three four five six seven eight nine".Split();
        var teens = " eleven twelve thir# four# fif# six# seven# eigh# nine#".Replace("#", "teen").Split();
        var tens = " ten twenty thirty forty fifty sixty seventy eighty ninety".Split();
        var thou = " thousand m# b# tr# quadr# quint# sext# sept# oct#".Replace("#", "illion").Split();
        var g = (v < 0) ? "minus " : "";
        var w = "";
        var p = 0;
        v = Math.Abs(v);
        while (v > 0)
        {
            int b = (int)(v % 1000);
            if (b > 0)
            {
                var h = (b / 100);
                var t = (b - h * 100) / 10;
                var u = (b - h * 100 - t * 10);
                var s = ((h > 0) ? units[h] + " hundred" + ((t > 0 | u > 0) ? " and " : "") : "")
                      + ((t > 0) ? (t == 1 && u > 0) ? teens[u] : tens[t] + ((u > 0) ? "-" : "") : "")
                      + ((t != 1) ? units[u] : "");
                s = (((v > 1000) && (h == 0) && (p == 0)) ? " and " : (v > 1000) ? ", " : "") + s;
                w = s + " " + thou[p] + w;
            }
            v = v / 1000;
            p++;
        }
        return g + w;
    }

Called using:

static void Main(string[] args)
{
  Console.WriteLine(wordify(decimal.MaxValue));
}

Output:

seventy-nine octillion, two hundred and twenty-eight septillion, one hundred and sixty-two sextillion, five hundred and fourteen quintillion, two hundred and sixty-four quadrillion, three hundred and thirty-seven trillion, five hundred and ninety-three billion, five hundred and forty-three million, nine hundred and fifty thousand, three hundred and thirty-five

๐ŸŒ
Reddit
reddit.com โ€บ r/codinghelp โ€บ convert numbers to words
r/CodingHelp on Reddit: Convert numbers to words
January 11, 2024 -

Hi!

I'm looking for a third party library in either Java or JavaScript that can convert numbers to words.

On the surface this isn't a majorly complex task, but my app will run inside documents so it needs to support all sorts of number types and anything else that can go with it. For example, numbers can be phone numbers, ZIP codes or just plain numbers. You can also have other symbols and characters beside the numbers like currency symbols and units of measurements. Is there anything out there that can convert this to words as well?

Examples Input - I have $3 Output - I have three dollars

Input - My ZIP code is 12345 and my car speed is 70mph. Output - My ZIP code is one two three four five and my car speed is seventy miles per hour.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ is converting numbers to words a hard challenge?
r/learnprogramming on Reddit: Is converting numbers to words a hard challenge?
July 7, 2023 -

Is it ok to struggle in programming a number to words converter? I tend to spend lots of time on such challenges and I'm pretty slow in finding solutions, is that a normal thing? Or am I just stupid for programming? I would like to hear from an experienced software engineer.

Edit: so many have misunderstood the task, by converting numbers to words I mean converting 1234567 to one million two hundred thirty-four thousand five hundred sixty-seven. It's basically like this: https://www.calculatorsoup.com/calculators/conversions/numberstowords.php

Top answer
1 of 22
87
Is it ok to struggle in programming Full stop. Yes. ;) Thinking like a programmer is hard. It's not something you do every day. It can take a while to get there. Programming is the art of breaking a single program in to many, more manageable, smaller ones. For your "a number to words converter," presumably we're talking about a function that takes a number and splits out something linguistic. e.g. f(1123) = "One thousand, one hundred, and twenty three". You'll need to break a number into discreet named bits. Anything over 100 has consistent rules. The tens spot above 19 is consistent. The teens are special cases, etc. I'd start with a single digit namer, because you'll use that in multiple cases. This mightn't immediately occur to you, but as you work through the problem and notice repetition, it should eventually. And that's part of the trick. The more you break problems down, the more you'll start to anticipate things you might need. It's ok to just do what you know is horrid code when starting a problem: you can always pretty it up later. Working the problem in code, in any way, no matter how wrong it might eventually end up being, will get you thinking about coding the problem. You could go down a number of wrong paths before you find the right one, but those dead ends will help you get there, in their own way.
2 of 22
62
I wrote a 17-line decimal to binary converter in Python and was so proud of it. Turns out there is a built-in function in Python that does this for you in 1 line. Safe to say I felt retarded. Itโ€™s ok to struggle.
๐ŸŒ
Numbers to Letters
numberstoletters.com
Numbers to Letters Converter | Fast, Free & Secure
To Words (1=One, 2 = Two, ... to Nonillion) ... Convert Single Number If Checked it will ignore number with it's together such as 15 will result in "o" and if not checked it will show "ae"
๐ŸŒ
Ablebits
ablebits.com โ€บ ablebits blog โ€บ excel โ€บ excel macro โ€บ how to convert number to words in excel
Two best ways to convert numbers to words in Excel
June 8, 2023 - It appears that Excel MVP, Jerry Latham, created such Excel User defined function (UDF) as WordsToDigits. It converts English words back to number. You can download Jerry's WordsToDigits workbook to see the UDF code.
๐ŸŒ
Browserling
browserling.com โ€บ tools โ€บ numbers-to-words
Numbers to Words Converter - Spell Numbers - Online - Browserling Web Developer Tools
World's simplest online numbers to text translator for web developers and programmers. Just paste your numbers in the form below, press the Convert button, and you'll get words. Press a button โ€“ get words.