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

fix: fix floating point issue in convertToMinorUnit [ROW-512] #194

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ describe('currency - convertToMinorUnit', () => {
`Error: The provided currency code is either empty or not supported. The received value was : ${unsupportedCurrencyCode}. Please ensure you pass a valid currency code.`,
);
});

it('should correctly convert amount to minor unit for INR', () => {
const result = convertToMinorUnit(4.14, { currency: 'INR' });
expect(result).toBe(414);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const convertToMinorUnit = (
const minorUnitMultiplier =
Math.pow(10, Number(currencyInfo.minor_unit)) || 100;

const lowerCurrencyValue = amount * minorUnitMultiplier;
const lowerCurrencyValue = parseFloat(
(amount * minorUnitMultiplier).toFixed(0),
);
return lowerCurrencyValue;
};

Expand Down
Loading