es.number.to-precision.js 800 B

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