Format numbers in scientific notation!
npm install scino --save
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:
num
<Number>
: Number to convert to scientific notationprecision
<Number>
: Optional precision to apply to the floatoptions
<Object>
: Optional formatting optionsAt 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>'
MIT. See LICENSE for details.