Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Step between 0 and 1 produces floating point rounding errors

Đang mở
#742 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ả

bug report v6

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstack/react-native-slider

Tất cả issue của callstack/react-native-slider

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.