# Can anyone write a block that turns digits into text?

Like:
[scratchblocks]
((83)as a word::operators)//Eighty three
[/scratchblocks]

I'll try, but it might take a while.

Is this your homework? It's a good exercise. My standard hint when I assign it is to start by writing a block that only turns the three-digit-group names to text:
123,456,789 -> "123 million, 456 thousand, 789"
Then write a block that turns a group of three digits into, e.g., "four hundred fifty-six," and then combine the two.

And start by loading the word/sentence library and the string library.

I've done

,but

To get rid of leading 0s, just add 0 to the input: .

Ah, I get to say this again: Get the words DOMAIN and RANGE tattooed on the insides of your eyelids. They're the most important words in computer science.

The domain of a function is the kind(s) of things it takes as inputs. (More formally, it's the set of all acceptable input values.) The range of a function is the kind(s) of things it reports.

What are the domain and range of your function? The range is easy; it's text strings. But what's the domain? Snap! makes this a little complicated because we have implicit conversion between numbers and strings of digits, but if you had to choose, is the input a number or a string? Actually I see that you know the answer, because the input slot in your picture is round. So the domain is numbers.

So you should use arithmetic functions on your input, and text functions (mainly JOIN) to construct your output. Instead of asking questions like

you should ask questions like

This is much better than worrying about leading zeros.

To really have fun once you get it to work, make it work for any bignum (after loading the bignum, ... library). There are different proposals for how to do this. I once implemented this one by John Conway who sadly died recently (of Covid).

E.g. 10^2631 is seseptuagintaoctingentillion

Good grief.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.