Skip to content

Commit dfcd6ba

Browse files
author
7yue
committed
fix(Counter): 修复浮点数数值超出问题
1 parent ac56e8a commit dfcd6ba

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/counter/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ Component({
114114
} else if (type === 'reduce') {
115115
result = count - step < min ? min : count - step;
116116
}
117+
// 浮点数运算会有精确度问题,保留两位小数
118+
result = result.toFixed(2);
119+
result = parseFloat(result);
117120

118121
this.setData({ count: result });
119122
eventUtil.emit(this, 'lintap', {

0 commit comments

Comments
 (0)