diff --git a/packages/amis-ui/src/components/NumberInput.tsx b/packages/amis-ui/src/components/NumberInput.tsx index 1a4f1a5e828..13d31211fe5 100644 --- a/packages/amis-ui/src/components/NumberInput.tsx +++ b/packages/amis-ui/src/components/NumberInput.tsx @@ -169,12 +169,12 @@ export class NumberInput extends React.Component { } } /** - * 非大数模式下,如果精度不满足要求,需要处理value值,遵循四舍五入的处理规则 + * 非大数模式下,如果精度不满足要求,需要处理value值,只做精度处理,不做四舍五入 */ if (!isBig && getNumberPrecision(value) !== precision) { - value = getMiniDecimal( - toFixed(num2str(value), '.', precision) - ).toNumber(); + const multiplier = Math.pow(10, precision); + const truncatedValue = Math.trunc(value * multiplier) / multiplier; + value = getMiniDecimal(truncatedValue).toNumber(); } return value; diff --git a/packages/amis/src/renderers/Form/InputNumber.tsx b/packages/amis/src/renderers/Form/InputNumber.tsx index b269f83e7df..42dbdcadcec 100644 --- a/packages/amis/src/renderers/Form/InputNumber.tsx +++ b/packages/amis/src/renderers/Form/InputNumber.tsx @@ -275,6 +275,7 @@ export default class NumberControl extends React.Component< // 大数下不需要进行精度处理,因为是字符串 big !== true ) { + // 精度处理,遵循四舍五入的处理规则 const normalizedValue = parseFloat( toFixed(value.toString(), '.', normalizedPrecision) );