I have been wondering around and found a lot of ways to remove .0 from doubles when formatting to strings but never found how to keep stuff for prices.
DecimalFormat format = new DecimalFormat();
format.setDecimalSeparatorAlwaysShown(false);
switch (position){
case 0:price = 11.90;break;
case 1:price = 1.2;break;
case 2:price = 1.002;break;
case 3:price = 1.0000;break;
}
System.out.println(format.format(price));
// 11.9
// or 1.2
// or 1.002
// or 1
but what i need is womthing like this
// 11.90
// 1.2
// or 1.002
// or 1
This is not a duplicate because that one will add 00 to any price which I don't want ... I am only looking to remove the floating point if there are zeros after it but to keep any zero there if there is a number.
e.g.
1.0, 1.00 or 1.00000
should print out 1
but
1.90, 1.900 or 1.90000
should print out the same 1.90, 1900 or 1.900000