2.9 Converting a number to a string

Since there is no special word in 4tH which will convert a number to a string, we'll have to create it ourselves. In the previous section we have seen how a numeric string is created in the PAD. We can use this to create a word that converts a number to a string.

Because the PAD is highly volatile, we have to move the string immediately after its creation. So we'll create a word that not only creates the string, but moves it directly to its proper location:

     : >string >r dup abs <# #s sign #> 1+ r> swap cmove ;
     ( n a -- )

It takes a number, the address of a string and returns nothing. Example:

     16 string num$
     -1024 num$ >string
     num$ count type cr