How to remove the decimal part from a float number that contains .0 in java

You could use a regular expression such as this: \\.0+$. If there are only 0's after the decimal point this regular expression will yield true.

Another thing you could do is something like so:

float x = 12.5;
float result = x - (int)x;
if (result != 0)
{
    //If the value of `result` is not equal to zero, then, you have a decimal portion which is not equal to 0.
}

If android gives you lemons. Dont throw it.

YourFormatedStringNumber = NumberFormat.getInstance().format(myNumber);

makes -> "12.50" to "12.50"  and "12.00" to "12"

More here in doc.

Tags:

Java

Android