0

How to delete zeroes in java (android) only if there is no non-zero value following them? The value is stored in double and then later in string, so working on these variables would be best.

Example: I have 12.50000 I want to have 12.5

Example2: I have 65.4030 I want to have 65.403

1 Answers1

0

Try this :

String s = 12.50000;
s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43