I was wondering on how to remove trailing 0s from whole numbers in my java program For example: 100.0 -> 100 However, for numbers like 1285.71 to remain the same.
I just need the trailing 0's from whole numbers removed, while still retaining the double value. I've tried:
double s = x / y;
String pattern = "0.#";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
System.out.println(decimalFormat.format(Double.valueOf(s)) );
However, does not working and i still get the annoying 0 after a whole number (100.0) Any help or insight would be much appreciated, cheers for your time.