Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I turn a number into words?

Asked by
Bubby4j 231 Moderation Voter
11 years ago

Say you have a number, make it 192,540,520

How can you turn this number into this string: one hundred ninety two million five hundred fourty thousand five hundred twenty

1 answer

Log in to vote
1
Answered by
AxeOfMen 434 Moderation Voter
11 years ago

This is a really fun exercise that involves recursion. I highly recommend attempting to work through this problem on your own before simply using the solution I present below. Take your time. Experiment with it. Have fun!

With that said, I present my solution here...

01local stringVals = {
02    [0] = "",
03    [1] = "one",
04    [2] = "two",
05    [3] = "three",
06    [4] = "four",
07    [5] = "five",
08    [6] = "six",
09    [7] = "seven",
10    [8] = "eight",
11    [9] = "nine",
12    [10] = "ten",
13    [11] = "eleven",
14    [12] = "twelve",
15    [13] = "thirteen",
View all 81 lines...

select output:

178 one hundred seventy eight

217 two hundred seventeen

334 three hundred thirty four

555 five hundred fifty five

685 six hundred eighty five

867 eight hundred sixty seven

1010 one thousand ten

1491 one thousand four hundred ninety one

1816 one thousand eight hundred sixteen

1998 one thousand nine hundred ninety eight

192540520 one hundred ninety two million five hundred forty thousand five hundred twenty

Ad

Answer this question