Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - calculate Math floor

Tags:

java

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
like image 417
Suganthan Madhavan Pillai Avatar asked Mar 07 '26 14:03

Suganthan Madhavan Pillai


2 Answers

My guess is it was meant to be:

Math.floor(value*100)/100;

Which essentially rounds value to two decimal places.

like image 136
Mark Peters Avatar answered Mar 10 '26 02:03

Mark Peters


Perhaps it's an error and they really wanted Math.floor(val*100)/100.0?

like image 27
Edward Doolittle Avatar answered Mar 10 '26 04:03

Edward Doolittle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!