currency-formatting

0.0.2 • Public • Published

currency-format

NPM

Coverage Status Build Status npm version Dependency Status devDependency Status

A small package that converts a number to currency format and visa versa.

Installation

Using cdn:

<script src="https://cdn.rawgit.com/tidupls/currency-format/master/dist/currency-format.min.js"></script>

Using npm:

$ npm install --save currency-formatting

Using bower:

$ bower install currency-formatting

Example

// Returns a formatted string.
// The number is formatted based on symbol, precision, decimal, thousand & format provided.
currency.format(5) // R 5.00
currency.format(500.555, '$') // $ 500.56
currency.format(4999.99, '', 2, '.', ',') // € 4.999,99
 
// Returns a number for the string provided.
currency.unformat('$ 500,00', ',') // 500
currency.unformat('£ 12,345,678.90 GBP', '.'); // 12345678.9

API

Has two public methods:

  • format(number, symbol, precision, thousand, decimal, format)
  • unformat(value, decimal)

and a global settings object with defaults of:

var settings = {
    symbol: "$", // default currency symbol
    format: "_s _v",    // format of currency _s = symbol & _v = value
    decimal: ".", // decimal point separator
    thousand: ",", // thousand separator
    precision: 2, // decimal places
}

Tests

$ npm run test

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    2
  • 0.0.1
    0

Package Sidebar

Install

npm i currency-formatting

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • tidupls