diff --git a/core-java-modules/core-java-lang-3/pom.xml b/core-java-modules/core-java-lang-3/pom.xml
index de290717b1..f98074ad1b 100644
--- a/core-java-modules/core-java-lang-3/pom.xml
+++ b/core-java-modules/core-java-lang-3/pom.xml
@@ -23,6 +23,18 @@
${assertj.version}
test
+
+ com.google.guava
+ guava
+ ${guava.version}
+ test
+
+
+ org.apache.commons
+ commons-math3
+ 3.6.1
+ test
+
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java
new file mode 100644
index 0000000000..c70dabd014
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java
@@ -0,0 +1,71 @@
+package com.baeldung.comparedouble;
+
+import com.google.common.math.DoubleMath;
+import org.apache.commons.math3.util.Precision;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+public class CompareDoubleUnitTest {
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingSimpleComparison_thenFails() {
+ double d1 = getFirstDouble(0);
+
+ double d2 = .1 * 8;
+
+ assertThat(d1 == d2).isFalse();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingThresholdComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+ assertThat(Math.abs(d1 - d2) < epsilon).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingGuavaFuzzyComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+
+ assertThat(DoubleMath.fuzzyEquals(d1, d2, epsilon)).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingCommonsMathComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+
+ assertThat(Precision.equals(d1, d2, epsilon)).isTrue();
+ assertThat(Precision.equals(d1, d2)).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingJunitComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+ assertEquals(d1, d2, epsilon);
+ }
+
+ private double getFirstDouble(double d1) {
+ for (int i = 1; i <= 8; i++) {
+ d1 += .1;
+ }
+ return d1;
+ }
+}
\ No newline at end of file