callstack / callstack/react-native-slider
Step between 0 and 1 produces floating point rounding errors
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.4k
- Forks
- 295
- Merge medio
- 5 min
- PR fusionados (30 d)
- 1
Descripción
## 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)}`
Guía de contribución
Línea de trabajo
Comienza ejecutando la reproducción proporcionada de Expo con minimumValue 0, maximumValue 1 y step 0.1 tanto en iOS como en Android. Rastrea dónde onValueChange recibe el valor calculado y, a continuación, verifica que los valores emitidos y los marcadores mostrados utilicen los pasos decimales esperados sin artefactos de coma flotante.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- react-native, typescript
- Área
- mobile-dev
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100