Namibian Pyjama Merchant

    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
    

    Install

    npm i currency-formatting

    DownloadsWeekly Downloads

    1

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • tidupls