callstack / callstack/react-native-slider
Step between 0 and 1 produces floating point rounding errors
- Ngôn ngữ chính
- TypeScript
- Star
- 1.4k
- Fork
- 295
- Merge trung bình
- 5 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
## 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)}`
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện Expo được cung cấp với minimumValue 0, maximumValue 1 và step 0.1 trên cả iOS và Android. Theo dõi vị trí onValueChange nhận giá trị đã tính toán, sau đó xác minh rằng các giá trị được phát ra và các marker được hiển thị sử dụng các bước thập phân như mong đợi mà không có lỗi hiển thị số dấu phẩy động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react-native, typescript
- Lĩnh vực
- mobile-dev
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100