|
1 | | -[](https://travis-ci.org/nashdot/accounting-js) |
2 | 1 | [](https://www.npmjs.com/package/accounting-js) |
3 | | -[](http://nashdot.github.io/accounting-js/docs) |
4 | 2 |
|
5 | 3 | **accounting-js** is a tiny JavaScript library for number, money and currency parsing/formatting. It's lightweight, fully localizable, has no dependencies, and works great client-side or server-side. Use standalone or as a nodeJS/npm and AMD/requireJS module. |
6 | 4 |
|
7 | | -[Documentation](http://nashdot.github.io/accounting-js/docs) |
| 5 | +[Documentation](http://nashdot.github.io/accounting-js) |
8 | 6 |
|
9 | | -Same as original [accounting.js](http://openexchangerates.github.io/accounting.js), but |
| 7 | +## Quickstart |
10 | 8 |
|
11 | | -* Rewritten with es6, respecting common style |
12 | | -* Using Rollup to produce UMD version |
13 | | -* Tested with [Ava](https://github.com/sindresorhus/ava), Coverage with [Nyc](https://github.com/bcoe/nyc) |
14 | | -* Applied corrections from |
15 | | - * @Lakshmi-Sharma |
16 | | - * @spidergears |
17 | | - * @jvc |
18 | | - * @latentflip |
19 | | - * @stevenbristol |
20 | | - * @samosad |
21 | | - * @solinas |
22 | | -* Published as [**accounting-js**](https://www.npmjs.com/package/accounting-js) on NPM |
| 9 | +### Install |
23 | 10 |
|
24 | | -Copyright (c) 2016 Nashdot, MIT License |
| 11 | +```shell |
| 12 | +npm install accounting-js |
| 13 | +``` |
| 14 | + |
| 15 | +### Use |
| 16 | + |
| 17 | +#### Format number |
| 18 | + |
| 19 | +```javascript |
| 20 | +import { formatNumber } from 'accounting-js'; |
| 21 | + |
| 22 | +// Default usage |
| 23 | +formatNumber(5318008); |
| 24 | +// ⇨ 5,318,008 |
| 25 | + |
| 26 | +// Custom format |
| 27 | +formatNumber(9876543.21, { precision: 3, thousand: " " }); |
| 28 | +// ⇨ 9 876 543.210 |
| 29 | +``` |
| 30 | + |
| 31 | +#### Format money |
| 32 | + |
| 33 | +```javascript |
| 34 | +import { formatMoney } from 'accounting-js'; |
| 35 | + |
| 36 | +// Default usage |
| 37 | +formatMoney(12345678); |
| 38 | +// ⇨ $12,345,678.00 |
| 39 | + |
| 40 | +// European formatting (custom symbol and separators) |
| 41 | +formatMoney(4999.99, { symbol: "€", precision: 2, thousand: ".", decimal: "," }); |
| 42 | +// ⇨ €4.999,99 |
| 43 | +``` |
| 44 | + |
| 45 | +#### Convert money to numeric |
| 46 | + |
| 47 | +```javascript |
| 48 | +import { unformat } from 'accounting-js'; |
| 49 | + |
| 50 | +unformat('£ 12,345,678.90 GBP'); |
| 51 | +// ⇨ 12345678.9 |
| 52 | +``` |
| 53 | + |
| 54 | +#### Accounting toFixed() |
| 55 | + |
| 56 | +```javascript |
| 57 | +// Native toFixed has rounding issues |
| 58 | +(0.615).toFixed(2); |
| 59 | +// ⇨ '0.61' |
| 60 | + |
| 61 | +// With accounting-js |
| 62 | +toFixed(0.615, 2); |
| 63 | +// ⇨ '0.62' |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | +Copyright (c) 2016-present Stanislav Lesnikov, MIT License |
25 | 68 |
|
26 | 69 | Copyright (c) 2014 Open Exchange Rates, MIT License |
0 commit comments