We shall get the long value by using Number
reference.
public static long toLong(Number number){
return number.longValue();
}
It works for all number types, here is a test:
public static void testToLong() throws Exception {
assertEquals(0l, toLong(0)); // an int
assertEquals(0l, toLong((short)0)); // a short
assertEquals(0l, toLong(0l)); // a long
assertEquals(0l, toLong((long) 0)); // another long
assertEquals(0l, toLong(0.0f)); // a float
assertEquals(0l, toLong(0.0)); // a double
}