Skip to content

Commit

Permalink
fix: 修复过早进行四舍五入,导致输入状态下自动格式化问题
Browse files Browse the repository at this point in the history
  • Loading branch information
F-jianchao authored and CheshireJCat committed Dec 12, 2024
1 parent c2e800d commit ae8db60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/amis-ui/src/components/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ export class NumberInput extends React.Component<NumberProps, NumberState> {
}
}
/**
* 非大数模式下,如果精度不满足要求,需要处理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;
Expand Down
1 change: 1 addition & 0 deletions packages/amis/src/renderers/Form/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export default class NumberControl extends React.Component<
// 大数下不需要进行精度处理,因为是字符串
big !== true
) {
// 精度处理,遵循四舍五入的处理规则
const normalizedValue = parseFloat(
toFixed(value.toString(), '.', normalizedPrecision)
);
Expand Down

0 comments on commit ae8db60

Please sign in to comment.