mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
fix/decimal-places (#10452)
This commit is contained in:
parent
e832bbf2c0
commit
92d3d7826d
1 changed files with 15 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue