pretty-number

1.0.7 • Public • Published

pretty-number unstable

Format number so it gets more humane format.

Usage

npm install pretty-number

const pretty = require('pretty-number');
 
pretty(10e+20) //10²¹
pretty(12e+20) //1.2 × 10²¹
pretty(1) //1
pretty(0) //0
pretty(-1) //−1
pretty(1.555e+20) //1.555 × 10²⁰
pretty(1.555e-15) //1.555 × 10⁻¹⁵
pretty(Infinity) //
pretty(-Infinity) //−∞
pretty(7.2973525664e-3, 3) //7.297 352 5664 × 10⁻³
pretty(72973525.664) //72 973 525.664
pretty(.123) //0.123
pretty(-.123) //−0.123
pretty(1.5) //1.5
pretty(-1.5) //−1.5
pretty(1e100) //10¹⁰⁰
pretty(-1e100) //−10¹⁰⁰
pretty(1e-100) //10⁻¹⁰⁰
pretty(-1e-100) //−10⁻¹⁰⁰
 
//indicate wishful precision
pretty(-0.000000005) //0
pretty(-0.000000005, 12) //−0.000 000 005

Formatting can be modified via constants:

pretty.multSign = '×';
pretty.minusSign = '';
pretty.spaceSign = '';
pretty.fractSign = '.';
pretty.precision = 9;

Note also that to make result look good custom font may be needed.

Related

mumath — set of practical math utils

Readme

Keywords

Package Sidebar

Install

npm i pretty-number

Weekly Downloads

11

Version

1.0.7

License

MIT

Last publish

Collaborators

  • dfcreative