 For this video, I'm using JShell, which is a utility that comes with the JDK from version 9 onwards. It's very handy for letting you test out Java constructs without having to write an entire program. For example, I can create an integer variable n and assign it the value 3 plus 4 times 5, and I'll get the result of 23. Let's see what happens if I take n and assign it the value 23 divided by 4. That's interesting. I get 5 instead of 5.75. That's because integers divided by integers always produce integer results. Let's try something different. Let's assign the result to a double variable. That should fix it. We'll set double D to become 23 divided by 4. Alas, no, that doesn't work either. Why? Because the right-hand side of the equal sign is evaluated before we even look at the left-hand side, and the right-hand side is an integer division, which gets a 5 as a result, which is then converted to a double 5.0. One solution is to make either of the operands a double by adding a decimal point. For example, D becomes 23.0 divided by 4, or D becomes 23 divided by 4.0. When you do arithmetic operations with a double and an integer, the integer is promoted to a double, and the result is a double. What happens if you try to go the other direction? If I say integer n becomes 23.0 divided by 4.0, Java doesn't let you do this conversion because it loses information. Okay, great, but what happens if you really, really want to convert a double to an integer, or if you have a program like this? Here, we ask for a number of items sold and the number of customers we had. Both of them are integers. You can't sell half a bicycle to half a person. But here in line 19, we have our problem of dividing integers by integers. Let's run the program and say that we sold 43 items to 4 people, and we get 10.0 instead of the result that we really want, which is 10.75. We can't add a decimal point to the variable name, such as total items 0.0. That just won't work at all. So what can we do? The answer is something called a cast. Think of it in the same sense as casting a metal into a mold to change its shape. To do a cast in Java, you precede the variable name with the data type that you want it to have. We want to promote total items to be a double, and then put that data type name in parentheses. We also want to promote the number of customers to be a double. Now we have a double divided by a double, which will give us a double result. Let's compile and let's run it. When we have 43 items with 4 customers, now we get an average with a decimal in it. This also gives us the solution to forcing conversion to a lesser data type. When we tried int n becomes 23.0 divided by 4.0, Java didn't let us do it. But we can say cast the result on the right hand side to be an integer. You need the parentheses around the division because you want the entire result converted to an integer, not just the 23.0. With this cast, Java is happy and we get the result we want. Why would you ever want to cast downwards, taking something with more precision to something with less precision? As the book says, this is what you can do in order to round a number down to a specific number of decimal places. For example, in this code, we're taking the tax which has 11.3845, multiplying it by 100 and converting it to an integer and then dividing by 100 again. Here's how it works. 11.3845 times 100 gives us 1138.45. Converting that to an integer gives us 1138. And dividing by 100 gives us 11.38. And that's how you use casts to convert data types.