Number to Text Manipulations

Scripts often convert numeric data to text data in order to display information to the user. Most of the time this conversion can be accomplished simply by using the coercion handler as, like in the following example:

12 as string--> Returns: "12"

However, some numeric values are displayed in scientific notation. For example, 1234000000 is displayed by a script as 1.234E+9

When this value is coerced to text it becomes: "1.234E+9"

The following sub-routine will convert any number to a string of numeric characters. This sub-routine is used by the other sub-routines on this page which also manipulate numeric data.

setsecond_partto (this_numbermod 1) div themod_valueif the length of (thesecond_partas text) is less than thedecimal_placesthenrepeatdecimal_places - (the length of (thesecond_partas text)) timessetsecond_partto ("0" & second_part) as stringend repeatend if

The following sub-routine will place leading zeros (0001, 023, etc.) before a number.

There are two passed parameters: the number to add leading zeros to, and the maximum number of leading zeros to add.

For example, if the maximum number of leading zeros is set to 2, then the results will range from 001 to 999. If the maximum number of leading zeros is 3, then the results will range from 0001 to 9999, and so on.