scurker/currency.js

BUG: If we set decimal as comma - we get an invalid value

Ph0enixKM opened this issue · 2 comments

Specification

Node version: 17
Currency.js version: 2.0.4

Problem

If we set ',' as the value for the decimal field in the settings object - we get a value that is 100 times bigger

How to reproduce

console.log(currencyJs('78.00', {decimal: ',' }).format())
// Output: "$7,800,00"

Here is a link to runkit example

This is expected.

What are you trying to accomplish? When you specify , as a decimal value, currency.js tries to parse any string inputs with your specified options. If you're trying to format your output string, you can pass the format options just into the format function:

currency("78.00").format({ decimal: "," })
// "$78,00"

Otherwise your input string needs to be the same as the specified format:

currency("78,00", { decimal: ',' }).format()
// "$78,00"

Thank you I must have misunderstood the usage.