swashcap / scino

Format numbers in scientific notation.
MIT License
0 stars 0 forks source link

Scino

Format numbers in scientific notation!

Installation

npm install scino --save

Use

Simply require scino in your program:

var scino = require('scino')

(You’ll need to use a module bundler like browserify to use scino in a browser.)

Scino is a function that has three parameters:

scino(num[, precision][, options])

At its most basic, scino formats numbers:

var formatted = scino(0.0012345)
console.log(formatted) // => '1.2345 × 10⁻³'

The numbers’ precision can be easily adjusted:

var formatted = scino(0.00051927528, 4)
console.log(formatted) // => '5.193 × 10⁻⁴'

Formatting options are also available:

var formatted = scino(-1234.56, {
  beforeCoefficient: '<strong>',
  afterCoefficient: '</strong>',
  multiplicationSign: '✖︎',
  beforeExponent: '<span>',
  afterExponent: '</span>'
})
console.log(formatted) // => '<strong>-1.23456</strong> ✖︎ 10<span>³</span>'

License

MIT. See LICENSE for details.