Sometimes a double can have an integer value and sometimes it can be a "real decimal digit".
I am searching for a way to print only the decimal digit if it has not a integer value:
public static void main(String[] args) {
double test = 1; // should print "1"
double test2 = 1.5; // should print "1,5"
System.out.println(String.format("%.1f", test)); // OUTPUT: "1,0"
System.out.println(String.format("%.1f", test2)); // OUTPUT: "1,5"
}
Thanks for your help guys!
Regards
Aucun commentaire:
Enregistrer un commentaire