Skip to content

Commit

Permalink
fix: 解决js浮点数计算有精度丢失问题 (#11465)
Browse files Browse the repository at this point in the history
  • Loading branch information
F-jianchao authored Jan 8, 2025
1 parent eed74d9 commit 4fc3844
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/amis-ui/src/components/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export class NumberInput extends React.Component<NumberProps, NumberState> {
*/
if (!isBig && getNumberPrecision(value) !== precision) {
const multiplier = Math.pow(10, precision);
const truncatedValue = Math.trunc(value * multiplier) / multiplier;
const truncatedValue =
Math.trunc(getMiniDecimal(value).multi(multiplier).toNumber()) /
multiplier;
value = getMiniDecimal(truncatedValue).toNumber();
}

Expand Down

0 comments on commit 4fc3844

Please sign in to comment.