1.0.7 • Published 8 years ago

pretty-number v1.0.7

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

#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

1.0.7

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago