I am storing a long value comes from backend system and I had to convert it to float because of one of the third party api only understands float. Now when I read back the float and trying to convert back to long I am getting a bigger number(some times I've seen smaller as well)than what I had.
My question is how can I get back the original number in long. I am happy to add any rounding logic if required
public class Main {
public static void main(String[] args) {
long item = 1502028000;
System.out.println(String.format("item -> %d",item));
float floatItem = item;
System.out.println(String.format("floatItem -> %f",floatItem));
long resultItem = (long)floatItem;
System.out.println(String.format("resultItem -> %d",resultItem));
}
}
Below is the output. I need my original number back which is 1502028000 in this case.
item -> 1502028000
floatItem -> 1502028032.000000
resultItem -> 1502028032
doubleinstead?