UNPKG

757 BJavaScriptView Raw
1'use strict';
2var $ = require('../internals/export');
3var fails = require('../internals/fails');
4var thisNumberValue = require('../internals/this-number-value');
5
6var nativeToPrecision = 1.0.toPrecision;
7
8var FORCED = fails(function () {
9 // IE7-
10 return nativeToPrecision.call(1, undefined) !== '1';
11}) || !fails(function () {
12 // V8 ~ Android 4.3-
13 nativeToPrecision.call({});
14});
15
16// `Number.prototype.toPrecision` method
17// https://tc39.es/ecma262/#sec-number.prototype.toprecision
18$({ target: 'Number', proto: true, forced: FORCED }, {
19 toPrecision: function toPrecision(precision) {
20 return precision === undefined
21 ? nativeToPrecision.call(thisNumberValue(this))
22 : nativeToPrecision.call(thisNumberValue(this), precision);
23 }
24});