Double to Integer Casting

This commit is contained in:
sreekanth.nair 2019-12-01 17:32:21 +05:30
parent b83316d625
commit 6913b18b13
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
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();
}
}