unitex
Unitex is a unit and number formatter that has wide coverage over unit formatting operations.
Usage
var unit = ; unit; // '1.234k'unit // '1 KB'
API
unit.format(number[, options])
options:
base - unit increment - default: 1000
prefix - current base exponent - default: 0
precision - output precision - default: 3
unit - unit symbol - default: '' (if not provided, there will be no space between the number and the unit prefix, override with '')
atomic - whether to use granular IEC units - default: false (for countable values, like bytes)
round - whether to round towards zero when atomic - default: false
trailing - whether output should have trailing zeros - default: false
delimiter - decimal separator - default: '.'
unit; // '1.234k'unit; // '1 KB'unit; // '5.5k'
unit.formatter(options)
Uses the same options as unit.format, but caches the options for convenience and better performance.
var fmt = unit;; // '1 KB'
Todo
- Implement inverse format