Java Floating-Point Comparison - double / float Variable Comparison with Epsilon - Java Programming

Опубликовано: 28 Сентябрь 2024
на канале: Appficial
7,499
102

Floating-point numbers should not be compared using == because some of these numbers cannot be exactly represented

You may expect them to be equal when comparing them, but instead they are just very close and == will come out as false

Therefore, floating-point numbers should not be compared for exact equality but instead for being close enough

The epsilon is a difference threshold for indicating that floating-point numbers are equal (it is usually 0.0001)

Please SUBSCRIBE to Appficial, and check out more Java Programming Tutorials! http://www.appficial.com

Java if else Statements
   • Java if else Statements - Branching S...  

Java Relational Operators
   • Java Relational Operators for Boolean...  

Java Multi-branch if-else-if Statement
   • Java Multi-branch if-else-if Statemen...  

Java Nested if-else Statements
   • Java Nested if-else Statements by Exa...  

Java Distinct If Statements
   • Java Distinct If Statements by Exampl...  

Java Logical Operators
   • Java Logical Operators - AND && - OR ...  

Java Short Circuit Evaluation
   • Java Short Circuit Evaluation - Lazy ...  

Java Switch Statement
   • Java Switch Statement - Branching Str...  

Java Precedence Rules for Logical and Relational Operators
   • Java Precedence Rules for Logical and...  

Java Boolean Data Type
   • Java Boolean Data Type by Example - T...  

Java String Comparison Methods
   • Java String Comparison Methods - equa...  

String Access Methods
   • Java String Access Methods - length c...  

String Modifier Methods
   • Java String Modifier Methods - toUppe...  

The Conditional Expression
   • Java Conditional Expression - The Ter...  

Floating-point Comparison
   • Java Floating-Point Comparison - doub...  

Character Comparison
   • Java Character Comparison - Comparing...  

System.out.printf() method
   • Java printf Method - Displaying data ...  

Displaying Currency in Java
   • Displaying Currency in Java using pri...  

Variable Scope
   • Variable Scope in a Java Program by E...