Hi I just came accross some legacy code, were I found one Math.floor() calculation
like Math.floor(value)*100/100. Just I trying to understand why they having that *100/100, because with and without this multiplication and division, I getting the same result.
Any suggesstions on why they having this calculation? At what situation this calculation will help me?
public class DoubleTest {
public static void main(String[] args) {
double val = 6.93904587395873495873493453453453454587349458734985739487857;
System.out.println(Math.floor(val)*100/100);
System.out.println(Math.floor(val));
}
}
Output
6.0
6.0
My guess is it was meant to be:
Math.floor(value*100)/100;
Which essentially rounds value to two decimal places.
Perhaps it's an error and they really wanted Math.floor(val*100)/100.0?
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