Here is my function to roundoff a number upto two decimals but when the rounded off number is 1.50 it seems to ignore the trailing zero and just returns 1.5
public static double roundOff(double number) {
double accuracy = 20;
number = number * accuracy;
number = Math.ceil(number);
number = number / accuracy;
return number;
}
So if I send 1.499 it returns 1.5 where as I want 1.50
This is a printing poblem:
double d = 1.5;
System.out.println(String.format("%.2f", d)); // 1.50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With