Home » JavaScript

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.

Examples:

    Input: 10
    num = 123.456

    Function call:
    num.toExponential(15)

    Output:
    1.234560000000000e+2

Code:

<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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.