mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-24 12:45:18 +08:00
fix(slider): fix floating point decimal precision (#750)
* fix(slider): fix floating point decimal precision * Update src/slider/src/Slider.tsx Co-authored-by: 07akioni <07akioni2@gmail.com> * Update src/slider/src/Slider.tsx Co-authored-by: 07akioni <07akioni2@gmail.com> * Update src/slider/src/Slider.tsx Co-authored-by: 07akioni <07akioni2@gmail.com> * fix(slider): fix floating point decimal precision * fix(slider): update changelog * Update CHANGELOG.en-US.md Co-authored-by: Yugang Cao <34439652+Talljack@users.noreply.github.com> * Update CHANGELOG.zh-CN.md Co-authored-by: Yugang Cao <34439652+Talljack@users.noreply.github.com> Co-authored-by: 07akioni <07akioni2@gmail.com> Co-authored-by: Yugang Cao <34439652+Talljack@users.noreply.github.com>
This commit is contained in:
parent
b3e17cb160
commit
85de0ec37b
@ -1,5 +1,13 @@
|
||||
# CHANGELOG
|
||||
|
||||
## Pending
|
||||
|
||||
### Feats
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix `n-slider` loss floating point decimal precision, closes [#751](https://github.com/TuSimple/naive-ui/issues/751).
|
||||
|
||||
## 2.16.0 (2021-08-02)
|
||||
|
||||
### Breaking Changes
|
||||
|
@ -1,5 +1,13 @@
|
||||
# CHANGELOG
|
||||
|
||||
## Pending
|
||||
|
||||
### Feats
|
||||
|
||||
### Fixes
|
||||
|
||||
- 修复 `n-slider` 丢失浮点数小数精度,关闭 [#751](https://github.com/TuSimple/naive-ui/issues/751)
|
||||
|
||||
## 2.16.0 (2021-08-02)
|
||||
|
||||
### Breaking Changes
|
||||
|
@ -114,6 +114,13 @@ export default defineComponent({
|
||||
const railRef = ref<HTMLElement | null>(null)
|
||||
const followerRef1 = ref<FollowerInst | null>(null)
|
||||
const followerRef2 = ref<FollowerInst | null>(null)
|
||||
const precisionRef = computed(() => {
|
||||
const precisions = [props.min, props.max, props.step].map((item) => {
|
||||
const fraction = String(item).split('.')[1]
|
||||
return fraction ? fraction.length : 0
|
||||
})
|
||||
return Math.max(...precisions)
|
||||
})
|
||||
|
||||
const uncontrolledValueRef = ref(props.defaultValue)
|
||||
const controlledValueRef = toRef(props, 'value')
|
||||
@ -459,6 +466,7 @@ export default defineComponent({
|
||||
justifiedValue = Math.max(min, justifiedValue)
|
||||
justifiedValue = Math.min(max, justifiedValue)
|
||||
justifiedValue = Math.round((justifiedValue - min) / step) * step + min
|
||||
justifiedValue = parseFloat(justifiedValue.toFixed(precisionRef.value))
|
||||
if (marks) {
|
||||
const closestMarkValue = getClosestMarkValue(value)
|
||||
if (
|
||||
|
Loading…
Reference in New Issue
Block a user