question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Step set 0.1 but get value 0.30000000000000004

See original GitHub issue

Environment

System: OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo) CPU: (8) x64 Intel® Core™ i7-4790 CPU @ 3.60GHz Memory: 1.13 GB / 15.55 GB Shell: 5.0.3 - /bin/bash Binaries: Node: 10.16.2 - /usr/local/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm SDKs: Android SDK: API Levels: 22, 23, 24, 25, 26, 27, 28, 29 Build Tools: 26.0.2, 28.0.3 System Images: android-22 | Intel x86 Atom, android-23 | Intel x86 Atom, android-25 | Google APIs ARM 64 v8a, android-27 | Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1

Description

Slider set step={0.1} onValueChange get value 0.30000000000000004

my code

<Slider 
       min={0}
       max={1} 
       step={0.1} 
       value={this.props.opacity} 
       maximumTrackTintColor="#000"
       minimumTrackTintColor="#56feb7"
       style={style.slider}
       thumbTintColor="#56feb7"
       thumbImage={require('../../../asset/image/slider.png')}
       onValueChange={this.changeOpac.bind(this)}></Slider>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Sharcouxcommented, May 7, 2020

This issue is due to computer’s handling of float numbers. It should be possible to fix it by using toFixed and parseFloat after rounding the value. Do you have a reproductible scenario?

0reactions
Sharcouxcommented, May 19, 2020

Fixed in @Sharcoux/slider version 3.2.0 Tell me if you encounter any issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Step set 0.1 but get value 0.30000000000000004 #163 - GitHub
This issue is due to computer's handling of float numbers. It should be possible to fix it by using toFixed and parseFloat after...
Read more >
0.1 + 0.2 returns 0.30000000000000004 @ Things Of Interest
Notice that this sum value, which we got by writing 0.1 + 0.2 , is a different JavaScript number from what we got...
Read more >
Implementing IEEE 754 in JS - YouTube
Floating point math is tricky. In this video, we'll learn how these numbers work in computers, and build a software implementation from ...
Read more >
Why »0.1 + 0.2« results in »0.30000000000000004« - Dev Tips
So the computer never »sees« 0.1 but the best approximation it can get. What is happening are the following steps. Converting 0.1 to...
Read more >
Why does the following code return 0.30000000000000004?
Why does the following code return 0.30000000000000004? function nfunc(f1, f2) { return f1 + f2 } console.log(nfunc(0.2, 0.1)); > ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found