So I use ...
System.out.printf("%.2f",variable);
and it works. But if the second decimal place is a 0
, it just ignores the zero and gives the answer to one decimal place. How can I get two decimal places including the zero?
Thanks.
So I use ...
System.out.printf("%.2f",variable);
and it works. But if the second decimal place is a 0
, it just ignores the zero and gives the answer to one decimal place. How can I get two decimal places including the zero?
Thanks.
you can use DecimalFormat like this
DecimalFormat decimalFormat = new DecimalFormat("#0.00");
String format = decimalFormat.format(variable);