Skip to content

Commit 3157bdb

Browse files
committed
Reduce floating point inaccuracies
1 parent 6351de9 commit 3157bdb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/InputSpinner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ class InputSpinner extends Component {
571571
if (!event && this.state.longStep > 0) {
572572
num = Math.round(num / this.state.longStep) * this.state.longStep;
573573
}
574+
if (this.isTypeDecimal()) {
575+
num = num.toFixed(this.props.precision) * 1
576+
}
574577

575578
if (
576579
this.isMaxReached(currentValue) &&
@@ -612,7 +615,10 @@ class InputSpinner extends Component {
612615
if (!event && this.state.longStep > 0) {
613616
num = Math.round(num / this.state.longStep) * this.state.longStep;
614617
}
615-
618+
if (this.isTypeDecimal()) {
619+
num = num.toFixed(this.props.precision) * 1
620+
}
621+
616622
if (
617623
this.isMinReached(currentValue) &&
618624
!this.isEmptied() &&

0 commit comments

Comments
 (0)