diff --git a/java-numbers/src/main/java/com/baeldung/casting/DoubleToInteger.java b/java-numbers/src/main/java/com/baeldung/casting/DoubleToInteger.java deleted file mode 100644 index 78af7f9f9d..0000000000 --- a/java-numbers/src/main/java/com/baeldung/casting/DoubleToInteger.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.casting; - -public class DoubleToInteger { - - static Double value = 99999.999; - - public static void main(String[] args) { - - System.out.println(usingIntValue(value)); - - System.out.println(usingMathRound(value)); - System.out.println(usingMathCeil(value)); - - System.out.println(usingMathFloor(value)); - System.out.println(usingMathAbs(value)); - } - - public static Integer usingIntValue(Double value) { - return value.intValue(); - } - - public static Integer usingMathRound(Double value) { - return (int) Math.round(value); - } - - public static Integer usingMathCeil(Double value) { - return (int) Math.ceil(value); - } - - public static Integer usingMathFloor(Double value) { - return (int) Math.floor(value); - } - - public static Integer usingMathAbs(Double value) { - return (int) Math.abs(value); - } - - public static Integer usingCast(Double value) { - return (int) value.doubleValue(); - } - -} diff --git a/java-numbers/src/test/java/com/baeldung/doubletolong/DoubleToLongUnitTest.java b/java-numbers/src/test/java/com/baeldung/doubletolong/DoubleToLongUnitTest.java new file mode 100644 index 0000000000..c34a3fcf13 --- /dev/null +++ b/java-numbers/src/test/java/com/baeldung/doubletolong/DoubleToLongUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.doubletolong; + +import org.junit.Assert; +import org.junit.Test; + +public class DoubleToLongUnitTest { + + final static double VALUE = 9999.999; + + @Test + public void using_longValue() { + Assert.assertEquals(9999L, Double.valueOf(VALUE) + .longValue()); + } + + @Test + public void using_Math_Round() { + Assert.assertEquals(10000L, Math.round(VALUE)); + } + + @Test + public void using_Math_Ceil() { + Assert.assertEquals(10000L, Math.ceil(VALUE), 0); + } + + @Test + public void using_Math_Floor() { + Assert.assertEquals(9999L, Math.floor(VALUE), 0); + } + + @Test + public void using_Type_Cast() { + Assert.assertEquals(9999L, (long) VALUE); + } + +}