scino
v1.0.2
Published
Format numbers in scientific notation.
Downloads
3
Maintainers
Readme
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])
num
<Number>
: Number to convert to scientific notationprecision
<Number>
: Optional precision to apply to the floatoptions
<Object>
: Optional formatting 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.