• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

2. Numbers and Dates > 2.1. Converting Between Numbers and Strings

Converting Between Numbers and Strings

NN 4, IE 4

Problem

You want to change a number data type to a string data type, or vice versa.

Solution

To convert a number value to a string value in Version 4 or later browsers, use the toString( ) method of a number value:

var numAsStringValue = numValue.toString( );

You can also create an instance of a String object by passing the number as an argument to the String object constructor:

var numAsStringObject = new String(numValue);

To convert a string to a number, use the parseInt( ) method if the desired result is an integer only, or the parseFloat( ) method if the number could be or is definitely a floating-point number:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint