Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

typescript
communitycreator

What is the toExponential() method in TypeScript?

Gutha Vamsi Krishna

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The toExponential() method is used to convert a number into an exponential notation.

Syntax

Here is the syntax of the toExponential() method:

number.toExponential(x)

Parameter value

This method takes a number as a parameter to represent the number of digits after a decimal point. The number must be in the range of 0 to 20.

Return value

​​This method returns a string value that represents the exponential notation of a given number.

Let's look at an example of this.

Example

let num = 6.57769;
//no.of digits after decimal is 1
console.log(num.toExponential(1))
//no.of digits after decimal is 3
console.log(num.toExponential(3))
//no.of digits after decimal is 8
console.log(num.toExponential(8))

Explanation

  • Line 1: We declare and initialize the number num.
  • Line 4: We convert the given number num to an exponential form, which has 1 digit after the decimal point.
  • Line 7: We convert the given number num to an exponential form, which has 3 digits after the decimal point.
  • Line 10: We convert the given number num to an exponential form, which has 8 digits after the decimal point.

          RELATED TAGS

          typescript
          communitycreator

          Grokking Modern System Design Interview for Engineers & Managers

          Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

          Keep Exploring