Socket
Socket
Sign inDemoInstall

to-exponential

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    to-exponential

Converts any big/small/precise decimal number represented as String, to exponential notation.


Version published
Maintainers
1
Install size
10.9 kB
Created

Readme

Source

to-exponential

Converts any arbitrarily big, small, or precise number represented as a String, to exponential notation. For regular numbers it works just like JavaScript's Number.toExponential().

The returned String can be used as a unique identifier for the number's value.

Specification

It accepts any decimal number represented as a String.

  • It converts it to exponential notation without loss of precision.
  • It works for high precision numbers, also for those that do not fit in a 64-bit JavaScript Number variable.
    (They still have to fit in Strings, which have some maximum length).
  • It works for very large and very small numbers, also for those with an exponent (e...) that does not fit in a 64-bit JS number.

The exponent always gets a sign (+ or -), consistent with the output of Number.toExponential(). So e.g. 5 becomes '5e+0' (not '5e0').

Returns false if the String does not represent a valid decimal number.

Install

npm install to-exponential

Examples

const toExponential = require('to-exponential');

console.dir( toExponential('0.5') );  // => '5e-1'.
console.dir( toExponential('5') );    // => '5e+0'.
console.dir( toExponential('50') );   // => '5e+1'.

console.dir( toExponential('10.5') );     // Outputs '1.05e+1'.
console.dir( toExponential('0.105e2') );  // Outputs '1.05e+1' too.

console.dir( toExponential(
  '-12324.3434716349863831487632112E-561640934731461387461933142'
) );
// => '-1.23243434716349863831487632112e-561640934731461387461933138'.

Keywords

FAQs

Last updated on 11 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc