Yahoo web space - 1135Chapter 42 .Global Functions and Statements parameter. By

1135Chapter 42 .Global Functions and Statements parameter. By setting this parameter between 2 and 16, you can convert numbers to string equivalents in different number bases. Listing 42-1 calculates and draws a conversion table for decimal, hexadecimal, and binary numbers between 0 and 20. In this case, the source of each value is the value of the index counter variable each time the for loop s statements execute. Listing 42-1: Using toString() with Radix Values Number Conversion Table Using toString() to convert to other number bases:


DecimalHexadecimalBinary
The toString() method of user-defined objects does not convert the object into a meaningful string, but you can create your own method to do just that. For example, if you want to make your custom object s toString() method behave like an array s method, then define the action of the method and assign that function to a property of the object (as shown in Listing 42-2). Listing 42-2: Creating a Custom toString() Method Custom toString()