scurker / currency.js

A javascript library for handling currencies
https://currency.js.org
MIT License
3.19k stars 143 forks source link

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

Closed Ph0enixKM closed 2 years ago

Ph0enixKM commented 2 years ago

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

scurker commented 2 years ago

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"
Ph0enixKM commented 2 years ago

Thank you I must have misunderstood the usage.