In this lecture, we'll look at how we can represent real numbers in a computer. And we actually have a real problem here, because real numbers are in what's called the continuous domain. We have an infinite number of real numbers between 0 and 1, for example. However, we also know that 2 to the b equal n. So if we have a limited number of bits which we do, we can only represent a certain number of distinct things. And so we can't represent real numbers from the continuous domain, in a computer with perfect accuracy. We need an infinite number of bits to do it. So in the computer, we're representing numbers in the discrete domain. When we represent things with 0s and 1s were representing things in the discrete domain. We can still represent numbers in computers, right. Computers were designed to do math. So we must be able to represent numbers somehow. And we can. The problem is, that we have to do or we have to accept some inaccuracy in our representations. This set of infinite real numbers will have groups of them that actually get represented with the same sequence of bits in the computer. So we can represent real numbers but we do it with some inaccuracy because we take groups of them and we put them all in the same bin of bits. That's how we have to work within the constraints of 2 to the b equal n. In C sharp, we represent those real numbers using something called floating point numbers. The most commonly used floating point data types in C sharp are float and double. And in our game development we're going to typically be using float. What's the difference between those two data types? Well, doubles have twice as many bits used to represent them as floats do. And because 2 to the b equal n, we know that doubles can represent twice as many unique values as floats can. The operations for floats and doubles are pretty much as you'd expect including division. So let's go take a look at a program that uses the float data type. I've already used visual studio to create a floating point data types project. I have added a documentation comment here and a documentation comment here, saying that my code is going to demonstrate floating point data types. I've also declared a couple of variables here. I've declared a score variable to say what score I earned in an action game. And I also have an inter variable for total seconds played, which is 10,000. Now I'm going to calculate and print the points per second. And some of you may be furious you may say well a real gamer would calculate DPS or damage per second instead. But, it's the same idea. We're here in this example, we're going to calculate and print points per second for an action game that I've played, even though I'm apparently not very good at it. So this is likely to be a decimal result. It will certainly be a decimal result in this case. So we don't want to store our points per second in inter variable because an invariable holds a whole number. We want to store it in a variable of a data type that can hold decimal numbers. And I'm going to use float as my data type and I'll name this variable point per second. And you'll notice I'm using exactly the same syntax I used to declare integer variables. I put the data type followed by the variable name and now I'm going to deliberately make a mistake and then we'll come back and fix it. So a reasonable way to calculate points per second, might seem to be score divided by total seconds played. I just hit tab a couple of times to accept the suggested code completion there. And now we need to print out the result, And I will label it here in this example but remember you won't label your output in auto graded programming assignments. But here I will, And I'll concatenate the value of the points per second variable and putting a semicolon at the end. When I run the code, you can see I get points per second is 0 and that is absolutely incorrect. The problem is, that score is an integer and total seconds played is an integer. So we do into your division here, which just gives us the quotient, the whole number quotient no remainder. One horrible way to solve this would be to change score to a float or to change total seconds played to a float but that would be a horrible solution because they're not floats. We should always pick an appropriate data type for the data that we're storing. And score as a whole number and total seconds played as a whole number. So making one of those afloat, is poor programming practice. What we really need to do, is we need to force this division to be floating point division, not integer division. And a good way to do that is to make either score or total seconds played, be treated as a float just for this division. The way I can say I want score to be afloat for this, is I do something called a typecast. And the way we do a typecast, is we put an open parenthesis, we put the data type that we want to cast to and we put a closed parenthesis. And that means that just here treat scores afloat, it doesn't change the underlying representation of score. The variable score, the variable is still an integer. But here for this calculation, cast that integer to afloat. Once we've done this, it will automatically convert total seconds plate to a float. So it will do floating point division and we'll get the correct answer. So I'll run the code again, and as you can see we get 0.136 points per second, which is a horrible stat. But it is correct mathematically for the values of those two variables. One other caution, you may decide now that you know about typecasting. You may decide well, I'll just put the typecast at the very beginning and I'll put everything into parentheses so it will do all this stuff and then it will type cast to a float. There's a problem with that approach because if I run my code you'll see I get 0 again. And the problem is, this is an integer, this is an integer. So it calculates an integer of 0 and says, okay, you can have the 0 as a float if you want. So the general rule that you should use, is that you should do a typecast as close to a variable or you will find out later method calls and so on. As close to the entity we want to cast as possible because if we try to move it away and typecast big chunks of calculations, it's probably not going to work the way you want it to. What we've learned as we looked at this floating point data types code, is we learned how to declare a variable as a float. And we also learned about typecasting and how valuable typecasting can be. In this particular example, we typecast to force a division to be floating point division rather than integer division. But we will learn later on, that we might want to typecast things that are doubles to be floats because we're regularly going to use floats in the code we write in the courses in the specialization. To recap, in this lecture we learned about the floating point data types in C Sharp. And we also learned that we get some inaccuracy when we try to represent the real numbers from the continuous domain as floating point numbers in the discrete domain in the computer. We can do it, but we get some inaccuracy when we do it.