Step between 0 and 1 produces floating point rounding errors
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react-native, typescript
- Lĩnh vực
- mobile-dev
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.
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 (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Slider
style={{ width: 300 }}
minimumValue={0}
maximumValue={1}
step={0.1}
value={value}
onValueChange={(val) => setValue(val)}
/>
<Text>Value: {value}</Text>
</View>
);
}
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)}
- Ngôn ngữ chính
- TypeScript
- Star
- 1.4k
- Fork
- 296
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của callstack/react-native-slider
-
Web: value={0} with a negative minimumValue renders the thumb at the minimumCó thể đã có người làm @huytdps13400 đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
callstack/react-native-slider#828 ·
-
Missing peerDependencies for react and react-native causes duplicate React instances in pnpm monoreposCó thể đã có người làm @patrickwehbe đã nhận 112 ngày trước. Đang mởbug report
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
callstack/react-native-slider#769 ·
-
bug report platform: iOS v6
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
callstack/react-native-slider#782 · 6 bình luận ·
-
iOS: negative min value and 0 as maximum value turns maximum to 1Có thể đã có người làm @huytdps13400 đã nhận 5 ngày trước. Đang mởbug report
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
callstack/react-native-slider#780 · 1 bình luận ·
-
bug report
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
callstack/react-native-slider#767 ·
Tất cả issue của callstack/react-native-slider
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
yjh051108/dsh-routing-suite#216 ·
-
kind/bug priority/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memoryCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 66/100
apache/fineract-consumer-facing#175 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 82/100
awslabs/visual-asset-management-system#413 ·
Maintainer thường phản hồi trong vòng 1 ngày