Welcome back.
In this video, I just want to quickly show you what happens when you try to store the result of a int
double mixed calculation inside of an int and inside of a double.
So if we have a variable here my int result and that will be my int divided by my double, you can see
that we're going to get an error if we now do the same thing with a double.
So my double result we'll see that we don't get an error.
That's because this int only can store int values.
So only whole numbers.
But the result of this will not be a whole number.
That's why we get this error here.
So that's something we cannot do.
But we can mix when we are using a double because a double can manage the integer here.
So if you divide a whole number by a decimal point number, you are going to get a decimal point result.
So here 0.617.
So we do get a double as a result.
And we get a proper result there.
So what if I instead of using a double here.
What if I just use a whole number.
So let's say eight okay.
Let's run this again.
And we see we get the result of zero.
Why do we get zero.
Because five divided by eight is 0.6 or something like that right.
So this just means that it cuts off the result.
So the result of this here is first of all going to be an int.
And whatever comes after that the decimal point is cut off.
So this means that this operation will result in zero.
That's why zero is stored.
Now if I change that to 8.0 suddenly I'm going to get the decimal result.
So 0.62 is the result here or 6.25 okay.
It goes in both directions right.
So as long as one of the values is a double, you will get a double as a result.
So we can check that out.
Plus five divided by three.
So this here again this will not be a double.
It's this this will just be one.
So basically we had 0.65 right.
Or 6.25.
Now we're going to get 1.625.
So let's run this.
And you see we get 1.625.
That's because five divided by three as an int is 15.0.
However divided by three is going to be 1.666.
So now you see we get a different result.
It says 2.2916666, which is the sum of 0.625 and 1.66666.
Okay.
So that's something you need to take into consideration whenever you're playing around with ints and
doubles when calculating.
And that also explains how we calculated the average last time.
But we only got a whole number.
So that's something you need to consider whenever you're working with doubles and ints and mixing them
together.