Javascript examples for Language Basics:Introduction
Useful Number-to-String Methods
Method | Description | Returns |
---|---|---|
toString() | Represents a number in base 10 | string |
toString(2) | Represents a number in binary | string |
toString(8) | Represents a number in octal | string |
toString(16) | Represents a number in hexadecimal | string |
toFixed(n) | Represents a real number with n digits after the decimal point | string |
toExponential(n) | Represents a number using exponential notation with one digit before the decimal point and n digits after | string |
toPrecision(n) | Represents a number with n significant digits, using exponential notation if required | string |
You can convert the numbers to strings with the toString method.
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> var myData1 = (5).toString() + String(5); document.writeln("Result: " + myData1); </script> </body> </html>//from www. j av a 2s . c om