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
|
// Assert
|
||||||
expect(parsed).toBe(2.07);
|
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
|
// Thousand seperators are not allowedd
|
||||||
const number = value.replace(/,/, ".");
|
const number = value.replace(/,/, ".");
|
||||||
const fractionDigits = getFractionDigits(locale, currency);
|
const fractionDigits = getFractionDigits(locale, currency);
|
||||||
const trimmedNumber = number.slice(
|
const lastDecimalPoint = number.lastIndexOf(".");
|
||||||
0,
|
const trimmedNumber = number.slice(0, lastDecimalPoint + 1 + fractionDigits);
|
||||||
number.lastIndexOf(".") + 1 + fractionDigits,
|
|
||||||
);
|
|
||||||
|
|
||||||
return parseFloat(trimmedNumber);
|
return parseFloat(lastDecimalPoint !== -1 ? trimmedNumber : number);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const prepareVariantChangeData = (
|
export const prepareVariantChangeData = (
|
||||||
|
|
Loading…
Reference in a new issue