Fix digits after decimal in input widget (#7468)
This commit is contained in:
parent
8679141c76
commit
2c08417829
|
|
@ -261,14 +261,22 @@ class InputComponent extends React.Component<
|
||||||
) {
|
) {
|
||||||
let value = valueAsString.split(",").join("");
|
let value = valueAsString.split(",").join("");
|
||||||
if (value) {
|
if (value) {
|
||||||
if (currentIndexOfDecimal !== indexOfDecimal) {
|
|
||||||
value = value.substr(0, currentIndexOfDecimal + fractionDigits + 1);
|
|
||||||
}
|
|
||||||
const locale = navigator.languages?.[0] || "en-US";
|
const locale = navigator.languages?.[0] || "en-US";
|
||||||
const formatter = new Intl.NumberFormat(locale, {
|
const formatter = new Intl.NumberFormat(locale, {
|
||||||
style: "decimal",
|
style: "decimal",
|
||||||
minimumFractionDigits: fractionDigits,
|
minimumFractionDigits: fractionDigits,
|
||||||
});
|
});
|
||||||
|
const decimalValueArray = value.split(".");
|
||||||
|
//remove extra digits after decimal point
|
||||||
|
if (
|
||||||
|
this.props.decimalsInCurrency &&
|
||||||
|
decimalValueArray[1].length > this.props.decimalsInCurrency
|
||||||
|
) {
|
||||||
|
value =
|
||||||
|
decimalValueArray[0] +
|
||||||
|
"." +
|
||||||
|
decimalValueArray[1].substr(0, this.props.decimalsInCurrency);
|
||||||
|
}
|
||||||
const formattedValue = formatter.format(parseFloat(value));
|
const formattedValue = formatter.format(parseFloat(value));
|
||||||
this.props.onValueChange(formattedValue);
|
this.props.onValueChange(formattedValue);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user