callstack / callstack/react-native-slider
Step between 0 and 1 produces floating point rounding errors
- 主要语言
- TypeScript
- 星标
- 1.4k
- 派生
- 295
- 平均合并
- 5 分钟
- 30 天内合并 PR
- 1
描述
## Environment
System:
OS: macOS
Binaries:
Node: v22.16.0
npm: 10.9.2
are you using the new architecture?
No (Expo-managed workflow)
which version of react & react-native are you using?
React: 19.1.0
React Native: 0.81.5
@react-native-community/slider: 5.0.1
Expo SDK: 54.0.17
## Description
when using minimumValue of 0, maximumValue of 1, and a step of 0.1, the value returned by onValueChange shows floating-point precision errors. Instead of returning decimal values (e.g. 0.4), it returns e.g. 0.4000000596046448, this can be seen in the value and the markers. Occurs consistently across iOS and Android in the Expo environment.
## Reproducible Demo
```
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import Slider from '@react-native-community/slider';
export default function App() {
const [value, setValue] = useState(0);
return (
setValue(val)}
/>
Value: {value}
);
}
```
## Potential Fix
Round the computed value before emitting it in onValueChange: `value = parseFloat(value.toFixed(6));`
## Workaround
For a temp workaround users can use:
`onValueChange={(val) => setValue(Math.round(val * 10) / 10)}`
贡献指南
调研方向
首先,在 iOS 和 Android 上运行提供的 Expo 复现,并使用 minimumValue 0、maximumValue 1 和 step 0.1。跟踪 onValueChange 接收计算值的位置,然后验证发出的值和显示的标记使用预期的小数步长,且没有浮点数伪影。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react-native, typescript
- 领域
- mobile-dev
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100