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

[Bug]: toUnits() swallows leading zeros on minor units #756

Open
2 tasks done
ameeuw opened this issue Sep 5, 2023 · 0 comments
Open
2 tasks done

[Bug]: toUnits() swallows leading zeros on minor units #756

ameeuw opened this issue Sep 5, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ameeuw
Copy link

ameeuw commented Sep 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The example given in the docs works as expected.

import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 1050, currency: USD });
const d2 = dinero({ amount: 10545, currency: USD, scale: 3 });

toUnits(d1); // [10, 50]
toUnits(d2); // [10, 545]

However if we change it to a leading zero in the minors, we lose this:

import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 1005, currency: USD });
const d2 = dinero({ amount: 10054, currency: USD, scale: 3 });

toUnits(d1); // [10, 5]
toUnits(d2); // [10, 54]

Expected behavior

import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 1005, currency: USD });
const d2 = dinero({ amount: 10054, currency: USD, scale: 3 });

toUnits(d1); // [10, 05]
toUnits(d2); // [10, 054]

As this is not possible, the "toUnits()" should return a string in order to preserve leading zeros.

Steps to reproduce

Use the above "Current behavior" example.

Version

2.0.0-alpha.14

Environment

Nodejs 14

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ameeuw ameeuw added the bug Something isn't working label Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants