Javatpoint Logo
Javatpoint Logo

JavaScript Number toPrecision() method

The JavaScript number toPrecision() method returns the string representing a number of specified precision.

Syntax

The toPrecision() method is represented by the following syntax:

Parameter

digits - It is optional. It represent the digits up to which the number must precise.

Return

A string that represents a number with exact digits after a decimal point

JavaScript Number toPrecision() method example

Here, we will understand toPrecision() method through various examples.

Example 1

Let's see a simple example of toPrecision() method.

Test it Now

Output:

99

Example 2

Let's see an example to fix a number up to given decimal point.

Test it Now

Output:

98.97

Next TopicJavaScript Number




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA