Converting to a String : Type Conversion : Number Data Type JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Number Data Type » Type Conversion »

 

Converting to a String












Booleans, numbers, and strings all have a toString() method to convert their value to a string.

The Boolean toString() method simply outputs the string "true" or "false".








var bFound = false;
alert(bFound.toString());    //outputs "false"



The Number toString() method has two modes: default and radix mode.

In default mode, the toString() method outputs the numeric value in an appropriate string.








var iNum1 = 10;
var fNum2 = 10.0;
alert(iNum1.toString());     //outputs "10"
alert(fNum2.toString());     //outputs "10"



In default mode, the Number's toString() returns the decimal representation of the number.





HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Number Data Type
» Type Conversion