To get the fraction point value up to two decimal points, I use this function:
double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("##.##");
return Double.valueOf(twoDForm.format(d));
But while there is a value like "5.50", then with this function I got only "5.5". Instead of that, I want to get the 5.50 with the above function. So what should I have to change?
Please give me the updated function or any suggestions to change the output like "0.00".
Your example works fine for rounding numbers to 2 digits. But you will lose trailing zeros, because numeric variables (double, float, ...) do not store any formating information.
If you want to see trailing zeros (like 5.50) you have to format the numbers on output:
DecimalFormat twoDForm = new DecimalFormat("#0.00");
System.out.println(twoDForm.format(d));