currency.js icon indicating copy to clipboard operation
currency.js copied to clipboard

Precision option is not valid for formatting

Open StebanDev opened this issue 4 years ago • 3 comments

Hi @scurker

I have an issue when passing the same parse options to the format method, it doesn't respect the precision option. I have looked in the source code and it doesn't appear, but I want to know if this is a bug or there is a reason to have it left behind.

e.g.

currency('5560.00').format({ decimal: ',', separator: '.', precision: 0 }) // expected: $5.560    actual: $5.560,00

If you need further details, please let me know, thank you for the great work!

StebanDev avatar Jan 27 '21 21:01 StebanDev

It looks like format only takes into account the precision of the original currency object. The only specific reason is generally currencies would keep the same precision for input/output. Is there a specific use case where you need a different precision for formatting?

scurker avatar Jan 28 '21 00:01 scurker

I know the default precision is 2 for parsing the value but I need the formatted value for the specific currency to have precision 0 for decimals so I think it would look nicer to pass this option to the format method instead of doing separately this which could work: currency('5560.00', { precision: 0 }).format({ decimal: ',', separator: '.' })

StebanDev avatar Jan 28 '21 04:01 StebanDev

It seems reasonable to allow currency.format() to accept similar options as the original currency function. I think precision is the only property that isn't accounted for, and there's been several requests for this. I would like to look into this soon but am also open to PRs.

scurker avatar Mar 09 '21 15:03 scurker