Skip to content

Commit

Permalink
fix: fix floating point issue in convertToMinorUnit [ROW-512] (#194)
Browse files Browse the repository at this point in the history
* fix: fix floating point issue in convertToMinorUnit

* add UT

* resolve review comments

* Create mean-pumas-deny.md
  • Loading branch information
RgnDunes authored Dec 16, 2024
1 parent 7f972ba commit 5bbace7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/mean-pumas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/i18nify-js": patch
---

fix floating point issue in convertToMinorUnit
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

0 comments on commit 5bbace7

Please sign in to comment.