Giovanni
Giovanni

Reputation: 129

Android get calculation result with decimal

I'm making some calculations on my project in order to see how many trucks could be parked on a road of X meters.

I have this:

    int road1 = 140;
    double trucks = 0;
    
    trucks = (road1-10)/20;
System.out.println("trucks"+trucks);

The problem is that if you calculate by yourself, the result will be 6.5. So you could park 6.5 trucks.

But I always get 6.0

Upvotes: 1

Views: 135

Answers (1)

Per.J
Per.J

Reputation: 1388

You are doing the calculation with ints, if you change to trucks = (road1-10)/20.0 you will get the answer 6.5

Upvotes: 4

Related Questions