Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Double to long without loosing the exact value

Tags:

java

I have a Double object which looses the exact value when converted to long value.

Double d = 1.14*100

System.out.println(d.longValue());

The above statement would print : 113.

I want 114 to be printed.

Thanks

like image 763
Abs Avatar asked Nov 08 '13 20:11

Abs


1 Answers

If you need the exact 114 value you ned to use Math.round:

double d = 1.14*100;
System.out.println(Math.round(d));
like image 159
Donvino Avatar answered Sep 30 '22 08:09

Donvino