the correct way to test floats for ‘equality’ is:
if(Math.abs(sectionID - currentSectionID) < epsilon)
where epsilon is a very small number like 0.00000001, depending on the desired precision.
More Related Contents:
- How do I compare strings in Java?
- What is the difference between == and equals() in Java?
- equals vs Arrays.equals in Java
- How to avoid floating point precision errors with floats or doubles in Java?
- Manipulating and comparing floating points in java
- How do you test to see if a double is equal to NaN?
- Java: How to test on array equality?
- Why aren’t Integers cached in Java?
- Does Java guarantee that Object.getClass() == Object.getClass()?
- String equality vs equality of location
- How default .equals and .hashCode will work for my classes?
- Rounding Errors?
- Difference between String#equals and String#contentEquals methods
- When “” == s is false but “”.equals( s ) is true
- Solving a “communications link failure” with JDBC and MySQL [duplicate]
- How do you create a REST client for Java? [closed]
- When should one use final for method parameters and local variables?
- Difference between Java SE/EE/ME?
- Wrap the string after a number of characters word-wise in Java
- Want an eclipse java project to run ant build files automatically
- Implementing a mouse click event on a tile in a map
- Having images as background of JPanel
- How can I show ellipses on my TextView if it is greater than the 1 line?
- Convert short to byte[] in Java
- Unable to get Struts2 Hello World to work using Eclipse and Maven
- How can I pass values between a Dialog and an Activity?
- Why does Java permit escaped unicode characters in the source code?
- org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:transformClassesWithDexForDebug’
- How does Spring 3 expression language interact with property placeholders?
- Are they any decent on-disk implementations of Java’s Map?