JavaScript Number method: toExponential()
[this page | pdf | back links]
The toExponential() method (when applied
to JavaScript
numbers) returns
a string representing the number in exponential notation, e.g. 301 is 3.01e+2.
It
has the following syntax with the following parameters:
number.toExponential(n)
Parameter
|
Required / Optional
|
Description
|
n
|
Optional
|
Integer between 0 and
20 indicating number of digits after decimal point
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var a = 123.48;
document.getElementById("Example").innerHTML =
'var a = ' + a + ';<br>' +
'var x = a.toExponential(1);';
document.getElementById("Result").innerHTML =
a.toExponential(1);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodNumberToExponential() {
var z = 12.5; return !!z.toExponential;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math