toPrecision() in javascript

     The toPrecision() method returns a string representing the Number object to the specified precision.

     A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits. See the discussion of rounding in the description of the Number.prototype.toFixed() method, which also applies to toPrecision().

     If the precision argument is omitted, behaves as Number.prototype.toString(). If the precision argument is a non-integer value, it is rounded to the nearest integer.

Syntax

   number.toPrecision([precision]);
Example

   (3.666621).toPrecision(2)  //3.37


Example Program:- (Editor)


Editor is Loading...

Advertisement

0 nhận xét:

Đăng nhận xét