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

FEAT: accept an object containing dollars and cents as separate fields #387

Open
Soviut opened this issue Apr 20, 2022 · 0 comments
Open

Comments

@Soviut
Copy link

Soviut commented Apr 20, 2022

Rather than needing to always use the { fromCents: true } option, it would be useful to also allow an object as the first argument which lets you enter the dollars and cents components independently.

currency({ dollars: 2 }) // return 2.00
currency({ cents: 50 })   // returns 0.50
currency({ cents: 250 })   // returns 2.50
currency({ dollars: 2, cents: 50 }) // returns 2.50

This would be similar to many date libraries allow you to build a date from discreet year, month, day, etc. components.

Possible edge case is if floats are used for dollars component. Perhaps it could only allow floored integers?

currency({ dollars: 2.25 }) // 2 or 2.25 ?
currency({ dollars: 2.25, cents: 50 }) // 2.25 or 2.50 ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant