TypeScript | toExponential() Method

The toExponential() method in TypeScript is used to convert a number to its exponential form. This method returns a string representing the given number object in exponential notation according to the given parameter.

Syntax: 

number.toExponential( [fractionDigits] )

Parameters: This method accepts a single parameter as mentioned above and described below:

  • fractionDigits: It is an integer value that specifies the number of digits after the decimal point. It is an optional parameter.

Return Value: The toExponential() method in TypeScript returns a string representing the number object in exponential notation with one digit before the decimal point.

Below examples illustrate the working of toExponential() method in TypeScript:



Example 1:

TypeScript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Define a number to find the
// exponential notation
var num1 = 2762.30
  
// Find the exponential value
var val = num1.toExponential();
  
// Display the value
console.log(val)

chevron_right


Output: 

2.7623e+3

Example 2:

TypeScript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Define a number to find the
// exponential notation
var num2 = 23456
  
// Find the exponential value
// with two digits after the
// decimal point
var val = num2.toExponential(2);
  
// Display the value
console.log(val)

chevron_right


Output: 

2.34e+4

full-stack-img

My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.