Java Retire los ceros finales del flotador

import java.text.DecimalFormat;


double example = 5.0; 
DecimalFormat myDF = new DecimalFormat("0.#");

//replace 'example' with the float you want to remove trailing zeros from.
System.out.println(myDF.format(example)); //output is 5

Step-Coder