number.prototype.toexponential

1.0.5 • Public • Published

Number.prototype.toExponential Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES-spec-compliant Number.prototype.toExponential shim/polyfill/replacement that works as far down as ES3

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Where this is needed

In particular:

  • Edge 15-17, and the equivalent versions of ChakraCore, have a rounding bug
  • IE <= 11, and Edge <= 14, have a different rounding bug
  • IE 6-8 do not properly throw on ±Infinity as fractionalDigits
  • FF 3.6-86 have a rounding bug
  • Safari < 11 and FF < 50 incorrectly throw on edge cases

If you are not concerned with supporting these engines, there is no need to use this package.

Note: ES2018 increased the maximum range from 20 to 100. This package does not attempt to patch this difference.

Getting started

npm install --save number.prototype.exponential

Usage/Examples

console.log((-3).toExponential()); // "-3e+0"
console.log(0x10.toExponential(2)); // "1.60e+1"
console.log(1.23456.toExponential(5)); // "1.23456e+0"
console.log((-6.9e-11).toExponential(4)); // "-6.9000e-11"

Tests

Clone the repo, npm install, and run npm test

Package Sidebar

Install

npm i number.prototype.toexponential

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

23.9 kB

Total Files

18

Last publish

Collaborators

  • ljharb