I write a code in Java
I have two numbers
For example
int alas = 15;
int tinggi = 3;
When I divide those two numbers
int luas = (alas * tinggi) / 2;
I want to have 7.5 as a result, but why it keeps shown as 7.0
I write a code in Java
I have two numbers
For example
int alas = 15;
int tinggi = 3;
When I divide those two numbers
int luas = (alas * tinggi) / 2;
I want to have 7.5 as a result, but why it keeps shown as 7.0
Try this:
double luas = (alas * tinggi) / 2.0;
when you divide int by int you will have int result. 2.0
mean that you want to divide by double, so result will be double.
int
there is no decimal places. you can use double
or float
.
double luas = (alas * tinggi) / 2.0;