I did clumsy,

double d= Double.valueOf("5.0596"); int i= (int) d; double d2= d- i; // дробная часть 

How can you do differently?

1 answer 1

As already advised, d%1 performs exactly what is needed, with the most syntactically short method. On the other hand, it is not necessarily the cheapest method in the calculation; Your "clumsy" method in this sense can be even better; if speed is important, it is better to make a benchmark compared to subtracting the whole part.

Note that int may not hold all integer values ​​for double within the limits where double represents all integers. For long, this is at least for a range where the step of double values ​​is 1 or less. And the conversion of larger values ​​works in such a way that it silently produces the corresponding extreme integer, so the result should be checked.