Basically toExponential method is used to convert a number into exponential form . In this method parameter is optional , if you write the parameter then this method do round the number otherwise not .
Syntax
numObj.toExponential ( [ fractionDigits ] )
Simple Example
var num = 10.657 ;
num.toExponential ( 2 ) ; // Output > return 10.66e+0 ....parameter passed : 2 i.e after decimal it will do round the number and return 2 digit after decimal
num.toExponential ( 3 ) ; // Output > return 10.656e+0
num.toExponential ( 5 ) ; // Output > return 10.65600e+0
Parameter ->
numObj -> It is mandatory ,a number object .
fractiondigits -> It is optional .After the decimal point , number of digits should be in range of 0 -20 .
Return Value ->
It return a string which represent the number in exponential form . And that string contain 1 digit befor the decimal point , and may contain fractiondigits after it .
Example
var num = new Number ( 100 ) ;
var exp = num.toExponential ( ) ;
document.write( exp ) ; // Output -> 1.00e+2
num = new Number ( 100.124 ) ;
exp =num.toExponential ( 6 ) ;
document.write( exp ) ; // Output -> 1.12456e+2
Error can be of two types in this method i.e
RangeError -> If fractiondigits range is too small or too large . It means its range should be in between 0 to 20 . Otherwise RangeError will come during execution .
TypeError -> If this method is invoked on an object that is not a Number
0 Comment(s)