fix/decimal-places (#10452)

This commit is contained in:
Shaurya Sharma 2024-07-30 09:41:21 +05:30 committed by GitHub
parent e832bbf2c0
commit 92d3d7826d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -258,6 +258,21 @@ export default function generateColumnsData({
color: textColor ?? '',
overflow: 'hidden',
};
const allowedDecimalPlaces = column?.decimalPlaces ?? null;
const removingExcessDecimalPlaces = (cellValue, allowedDecimalPlaces) => {
allowedDecimalPlaces = resolveReferences(allowedDecimalPlaces);
if (cellValue?.toString()?.includes('.')) {
const splittedCellValue = cellValue?.toString()?.split('.');
const decimalPlacesUnderLimit = splittedCellValue[1].split('').splice(0, allowedDecimalPlaces).join('');
cellValue = Number(`${splittedCellValue[0]}.${decimalPlacesUnderLimit}`);
}
return cellValue;
};
cellValue = allowedDecimalPlaces ? removingExcessDecimalPlaces(cellValue, allowedDecimalPlaces) : cellValue;
if (isEditable) {
const validationData = validateWidget({
validationObject: {
@ -301,23 +316,6 @@ export default function generateColumnsData({
}
};
const allowedDecimalPlaces = column?.decimalPlaces ?? null;
const removingExcessDecimalPlaces = (cellValue, allowedDecimalPlaces) => {
allowedDecimalPlaces = resolveReferences(allowedDecimalPlaces);
if (cellValue?.toString()?.includes('.')) {
const splittedCellValue = cellValue?.toString()?.split('.');
const decimalPlacesUnderLimit = splittedCellValue[1]
.split('')
.splice(0, allowedDecimalPlaces)
.join('');
cellValue = Number(`${splittedCellValue[0]}.${decimalPlacesUnderLimit}`);
}
return cellValue;
};
cellValue = allowedDecimalPlaces
? removingExcessDecimalPlaces(cellValue, allowedDecimalPlaces)
: cellValue;
return (
<div className="h-100 d-flex flex-column justify-content-center position-relative">
<input