I am trying to cut the decimal off the output of this small code:
import java.util.Scanner;
public class Distance {
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner( System.in );
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
double X= Math.pow((x2-x1),2);
double Y= Math.pow((y2-y1),2);
double d = Math.sqrt(X + Y);
System.out.println("Distance is: "+d);
}
}
Lets say output is 5192.237545685454687.
I want the output to be 5192.23...
So how do i cut it off by 2 decimal places?