Fix cut numbers (#3072)
This commit is contained in:
parent
6dbb8e4ecc
commit
83962d6e93
2 changed files with 15 additions and 5 deletions
|
@ -64,4 +64,16 @@ describe("parseCurrency", () => {
|
|||
// Assert
|
||||
expect(parsed).toBe(2.07);
|
||||
});
|
||||
it("should not trim price without decimal", () => {
|
||||
// Arrange
|
||||
const value = "2123";
|
||||
const currency = "EUR";
|
||||
const locale = Locale.PL;
|
||||
|
||||
// Act
|
||||
const parsed = parseCurrency(value, locale, currency);
|
||||
|
||||
// Assert
|
||||
expect(parsed).toBe(2123);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,12 +26,10 @@ export const parseCurrency = (
|
|||
// Thousand seperators are not allowedd
|
||||
const number = value.replace(/,/, ".");
|
||||
const fractionDigits = getFractionDigits(locale, currency);
|
||||
const trimmedNumber = number.slice(
|
||||
0,
|
||||
number.lastIndexOf(".") + 1 + fractionDigits,
|
||||
);
|
||||
const lastDecimalPoint = number.lastIndexOf(".");
|
||||
const trimmedNumber = number.slice(0, lastDecimalPoint + 1 + fractionDigits);
|
||||
|
||||
return parseFloat(trimmedNumber);
|
||||
return parseFloat(lastDecimalPoint !== -1 ? trimmedNumber : number);
|
||||
};
|
||||
|
||||
export const prepareVariantChangeData = (
|
||||
|
|
Loading…
Reference in a new issue