Javascript Multilingual Number Format Library | numbro

numbro is a javascript library for formatting and manipulating numbers. numbro is a powerful JavaScript number format library used to convert, format, and manipulate numbers with support for currency, time, percentage, and more.

How to make use of it:

Install and import the numbro module into your undertaking.

# NPM
$ npm install numbro --save

# Bower
$ bower install numbro --save
// ES 6
import numbro from 'numbro';

// CommonJS:
const numbro = require('numbro');

Or embody the JavaScript file immediately on the webpage.

<script src="/dist/numbro.min.js"></script>

The JavaScript to format numbers you provide.

var string = numbro(10001).format({
    thousandSeparated: true,
    mantissa: 4
});
=> 10,001.0000

var string = numbro(10000.12).format({
    thousandSeparated: true,
    forceSign: true
});
=> +10,000.12

var string = numbro(1.23456).format({
    trimMantissa: true,
    mantissa: 4
});
=> 1.2346

var string = numbro(-10000).format({
    thousandSeparated: true,
    negative: "parenthesis",
    mantissa: 4
});
=> (10,000.0000)

var string = numbro(1234567).format({
    average: true,
    mantissa: 1
});
=> 1.2m

var string = numbro(-123456).format({
    spaceSeparated: false,
    average: true
});
=> -103k

var string = numbro(100).format({
    output: "ordinal"
});
=> 100th

var string = numbro(1234567891).format({
    average: true,
    totalLength: 3
});
=> 1.23b

Format currencies:

var string = numbro(1000.123).formatCurrency({
    thousandSeparated: true,
    mantissa: 2
});
=> 1,000.12

var string = numbro(1000.1).formatCurrency({
    average: true,
    mantissa: 2,
    optionalMantissa: true,
    currencyPosition: "postfix",
    spaceSeparated: true
});
=> 1k

var string = numbro(-1000.123).formatCurrency({
    thousandSeparated: true,
    negative: "parenthesis"
});
=> (1,000.123)

Format bytes:

var string = numbro(20).format({
    output: "byte",
    base: "binary"
});
=> 20B

var string = numbro(1024).format({
    output: "byte",
    base: "binary",
    spaceSeparated: true
});
=> 1 KiB

var string = numbro(1024).format({
    output: "byte",
    base: "binary",
    mantissa: 3,
    spaceSeparated: true
});
=> 1.024 KiB

Format percentages:

var string = numbro(0.5).format({
    output: "percent"
});
=> 50%

var string = numbro(0.12345).format({
    output: "percent",
    mantissa: 2
});
=> 12.34%

var string = numbro(-0.52).format({
    output: "percent",
    spaceSeparated: true
});
=> -52 %

var string = numbro(0.52).format({
    output: "percent",
    mantissa: 3,
    negative: "parenthesis",
    spaceSeparated: true
});
=> 52.000 %

Format a DateTime string.

var string = numbro(63846).format({
    output: "time"
});
=> 17:44:06

Unformat a string.

var string = numbro.unformat('($10,000.00)');

Manipulate the numbers with the next 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

Convenient Multi-language Number Formatting Library, numbro Plugin/Github, numbro npm, auto format number input


See Demo And Download

Official Website(BenjaminVanRyseghem): Click Here

This superior jQuery/javascript plugin is developed by BenjaminVanRyseghem. For extra advanced usage, please go to the official website.

Related Posts

bootstrap-dropdown-on-hover

[Animation] Bootstrap Multi-Level Responsive Dropdown Menu

Bootstrap-based multi-level dropdown navigation menu with cool animations. The dropdown on Hover is a jQuery plugin used to create Bootstrap multi-level scroll-triggered dropdown menus with CSS3 animations…

Google-Translate-Dropdown-Customize-With-Country-Flag

Google Translate Dropdown Customize With Country Flag | GT API

Flag google translates jQuery text that takes advantage of the Google Cloud Translation API to translate web content between languages by selecting a country from the dropdown…

Bootstrap-Fileinput

HTML 5 File Input Optimized for Bootstrap 4.x./3.x with File Preview | Bootstrap Fileinput

bootstrap-fileinput is an improved HTML 5 file input  Bootstrap 5.x, 4.x and 3.x with file preview for different files, provides multiple selections, resumable section uploads, and more….

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Bootstrap-4-Toast-Notification-Plugin

Lightweight Bootstrap 4 Toast Notification Plugin | BS4 Advanced Toast

A lightweight Bootstrap 4 Toast Notification plugin integrated with JS/jQuery. bs4-toast.js is a JavaScript library that enhances the native Bootstrap toast component with icons, buttons, callbacks, and…

Leave a Reply

Your email address will not be published. Required fields are marked *