Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
format-currency
Advanced tools
format-currency
is a JavaScript component to format numbers and strings to currency strings. Used in Exodus Ethereum Wallet.
npm install --save format-currency
Object.assign
and Intl.NumberFormat
.
In Node.js, this is at least v4. You can install in older environments, you'll just
need to polyfill.Signature: formatCurrency(value, [options])
Parameters:
value
: Value to convert. Will pass through parse-num first.
Will coerce anything to a number.options
: optional object
parameter to specify options.
Appending Digits
is not necessary. You can also shorten maximum
to max
and minimum
to min
. Adds one more option nanZero
, which when the number is
NaN
, if it should be coerced to 0
- defaults to true
i.e. NaN => '0'
. Also available code
, symbol
, format
.Returns:
A string
currency representation of the number.
Example:
const formatCurrency = require('format-currency')
// default, no currency symbol or code
console.log(formatCurrency(10000000.15)) // => 10,000,000.15
// include the currency code 'USD'
let opts = { format: '%v %c', code: 'USD' }
console.log(formatCurrency(10000000.15, opts)) // => 10,000,000.15 USD
// now include the currency symbol
let opts = { format: '%s%v %c', code: 'USD', symbol: '$' }
console.log(formatCurrency(10000000.15, opts)) // => $10,000,000.15 USD
// use to reformat currency strings
let opts = { format: '%s%v', symbol: '$' }
console.log(formatCurrency('$10,000,000.15 USD', opts)) // => $10,000,000.15
// change locale
let opts = { format: '%s%v', symbol: '$', locale: 'de-DE' }
// in Node.js (English only, unless you compiled with other language support)
console.log(formatCurrency(10000000.15, opts)) // => $10,000,000.15
// in Electron (renderer) or browser (supports all locales)
console.log(formatCurrency(10000000.15, opts)) // => $10.000.000,15
// crypto currency (Bitcoin, Ethereum)
let opts = { format: '%v %c', code: 'BTC', maxFraction: 8 }
console.log(formatCurrency(1.123456789, opts)) // => 1.12345678 (notice only 8)
MIT
1.0.0 / 2016-03-17
FAQs
Format strings or numbers to currency strings.
The npm package format-currency receives a total of 3,938 weekly downloads. As such, format-currency popularity was classified as popular.
We found that format-currency demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.