Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision option is not valid for formatting #293

Open
StebanDev opened this issue Jan 27, 2021 · 3 comments
Open

Precision option is not valid for formatting #293

StebanDev opened this issue Jan 27, 2021 · 3 comments

Comments

@StebanDev
Copy link

StebanDev commented Jan 27, 2021

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!

@scurker
Copy link
Owner

scurker commented Jan 28, 2021

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?

@StebanDev
Copy link
Author

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: '.' })

@scurker
Copy link
Owner

scurker commented Mar 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants