Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/swashcap/scino

Format numbers in scientific notation.
https://github.com/swashcap/scino

Last synced: about 2 months ago
JSON representation

Format numbers in scientific notation.

Awesome Lists containing this project

README

        

# Scino

_Format numbers in scientific notation!_

## Installation

```shell
npm install scino --save
```

## Use

Simply `require` scino in your program:

```js
var scino = require('scino')
```

(You’ll need to use a module bundler like [browserify](https://github.com/substack/node-browserify#readme) to use scino in a browser.)

Scino is a function that has three parameters:

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

* **`num`** ``: Number to convert to scientific notation
* **`precision`** ``: Optional precision to apply to the float
* **`options`** ``: Optional formatting options

At its most basic, scino formats numbers:

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

The numbers’ precision can be easily adjusted:

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

Formatting options are also available:

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

## License

MIT. See [LICENSE](./LICENSE) for details.