Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including format-price with all npm packages installed. Try it out:

var formatPrice = require("format-price")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

format-price v0.0.2

Parse and format things that could be prices

format-price

Build Status

Simple utility to deal with formatting and parsing price. When asking a user to input a price, you should expect just about anything:

US$ 3.900,90-
-£5,016.43
-$8,202.97
100,000,000.90
100.000.000,99
19,95 €
€ 19.99
$1,-

So unless we restrict the user, we have to deal with this.

install

npm install format-price

usage


    var Price = require('format-price');

    var amount = Price.parse('US$ 3.900,90-');
    // =>  -3900.90

methods

parse

This is a RegExp based price parser, and it should be able to deal with most (western) number formatting, as provided by Intl.NumberFormat. See the examples in the introduction.

format

Format a number according to locale and currency:

    Price.format( 'fr-FR', 'EUR', 19.99 );
    // => 19,99 €

This is really just a small wrapper around Intl.NumberFormat provided for symetry and shorter code.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free