Skip to content

Commit 1f399f5

Browse files
Merge pull request #41 from selsamman/master
fix: reduce Floating Point Inaccuracy
2 parents 02b218b + 73f07b2 commit 1f399f5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/InputSpinner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ class InputSpinner extends Component {
595595
if (isLongPress && this.state.longStep > 0) {
596596
num = Math.round(num / this.state.longStep) * this.state.longStep;
597597
}
598+
if (this.isTypeDecimal()) {
599+
num = Number(num.toFixed(this.props.precision));
600+
}
598601

599602
if (
600603
this.isMaxReached(currentValue) &&
@@ -660,6 +663,9 @@ class InputSpinner extends Component {
660663
if (isLongPress && this.state.longStep > 0) {
661664
num = Math.round(num / this.state.longStep) * this.state.longStep;
662665
}
666+
if (this.isTypeDecimal()) {
667+
num = Number(num.toFixed(this.props.precision));
668+
}
663669

664670
if (
665671
this.isMinReached(currentValue) &&

0 commit comments

Comments
 (0)