Ankit Ankit - 2 years ago 146
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download