51
Convenient Multi-language Number Formatting Library – numbro
source link: https://www.tuicool.com/articles/hit/MJFJVj3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Author:
BenjaminVanRyseghem
Views Total:
604
Official Page:
Go to website
Last Update:
January 19, 2019
License:
MIT
Preview:
Description:
numbro is a robust number formatting JavaScript library used for converting, formatting, and manipulating numbers with support for currency, time, percentage, and much more.
Basic usage:
Install and import the numbro module into your project.
# NPM $ npm install numbro --save # Bower $ bower install numbro --save
// ES 6 import numbro from 'numbro'; // CommonJS: const numbro = require('numbro');
Or include the JavaScript file directly on the webpage.
<script src="/dist/numbro.min.js"></script>
The JavaScript to format numbers you provide.
var string = numbro(10000).format('0,0'); // => '10,000'
Manipulate the numbers with the following API.
var number = numbro(10000); // 10010 var added = number.add(10); // 9900 var added = number.subtract(100) // 100000 var added = number.multiply(10) // 1000 var added = number.divide(10) // sets a new value number.set(1000); // finds the differences value = 100; var difference = number.difference(value); // clones bumbers var a = numbro(1000); var b = numbro(a); var c = a.clone(); var aVal = a.set(2000).value(); // 2000 var bVal = b.value(); // 1000 var cVal = c.add(10).value(); // 1010
Changelog:
v2.1.2 (01/19/2018)
- Fix: Update dependencies
- Fix: Small changes to doc comments
- Fix: Fixed unformat for non standard delimiters
v2.1.1 (10/18/2018)
- Truncated numbers with trimMantissa and zero mantissa.
- Fixes duplicate call of chooseLanguage when setting a language without subtag.
- Enable es6 imports when using typescript.
07/14/2018
- Fixes duplicate call of chooseLanguage when setting a language without subtag
- Fixes duplicate call of chooseLanguage when setting a language without subtag
- Fixes duplicate call of chooseLanguage
- Add unit test for setLanguage
06/14/2018
- Release 2.1.0
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK