Ankit Ankit - 4 months ago 12
Java Question

How to check if a double value has no decimal part

I have a double value which I have to display at my UI.
Now the condition is that the decimal value of double = 0 eg. - 14.0
In that case I have to show only 14 on my UI.
Also, the max limit for characters is 5 here.

eg.- 12.34 the integer value can be no bigger than 2 digits and so is the decimal value for our double.

What could be the best way of doing this?

Answer

You could simply do this: d % 1 == 0 to see if some double d is whole.