Nietzsche's Preposterous Moustache
Miss any of our Open RFC calls?Watch the recordings here! »

cur

1.0.3 • Public • Published

CircleCI styled with prettier minified

cur

If you want to format currency, it'll cost you 1kb.

Installation:

npm i -S cur@latest

Usage:

cur(
    figureToBeFormatted: number,
    returnDollarsAndCents: boolean, 
    config: { thousandsSeparator: string, decimalSeparator: string }
) => string | undefined

Example with cents:

const cur = require('cur')
const dollars = 1234.56
const formattedDollars = cur(dollars, true)

console.log(`$${formattedDollars}`)
// =>  $1,234.56

Example without cents:

import cur from 'cur'
const dollars = 1234.56
const formattedDollars = cur(dollars)

console.log(`$${formattedDollars}`)
// =>  $1,235

Separators:

cur accepts an optional config argument with two properties, thousandsSeparator and decimalSeparator.

const formatCurrency = require('cur')
const config = { thousandsSeparator: "'", decimalSeparator: "," }
const amount = 1234.56
const formattedAmount = formatCurrency(amount, true, config)

console.log(formattedAmount)
// => 1'234,56

Install

npm i cur

DownloadsWeekly Downloads

5

Version

1.0.3

License

ISC

Last publish

Collaborators

  • avatar