×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

Number toExponential() Method with Example in JavaScript

JavaScript Number toExponential() Method: Here, we are going to learn about the toExponential() method with example.
Submitted by IncludeHelp, on February 20, 2019

Number toExponential() Method

toExponential() method is a method of Number class, it is used to convert a number into exponential notation format.

Syntax

Number.toExponential([n]);

Here, n is an optional parameter, it is used to define the number of digits from 0 to 20 in the notation format.

Example

Input: 10
num = 123.456

Function call:
num.toExponential(15)

Output:
1.234560000000000e+2

Example - Use of Number toExponential() Method

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
	var num = 123.456;
	
	var exp_res1 = num.toExponential();
	var exp_res2 = num.toExponential(2);
	var exp_res3 = num.toExponential(15);
	
	document.write("exp_res1 = " + exp_res1 + "<br>");
	document.write("exp_res2 = " + exp_res2 + "<br>");
	document.write("exp_res3 = " + exp_res3 + "<br>");
	
</script>
</body>
</html>

Output

exp_res1 = 1.23456e+2
exp_res2 = 1.23e+2
exp_res3 = 1.234560000000000e+2

JavaScript Number Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.