Convenient Multi-language Number Formatting Library – numbro

Category: Javascript , Recommended | January 9, 2018
Author: BenjaminVanRyseghem
Views Total: 46
Official Page: Go to website
Last Update: January 9, 2018
License: MIT

Preview:

Convenient Multi-language Number Formatting Library – numbro

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

Leave a Reply