Okay.
So next up in this onslaught of data types, we're going to discuss some important numeric types.
So there are quite a few we've already discussed inte we've used it quite a bit.
It works with whole numbers.
So it's useful if you're working with things where you need them or want them to be whole numbers where
decimals don't matter.
So we know how it works at this point.
However, there are a bunch of other data types that MySQL comes with.
We're not going to talk about every single one.
We're just going to talk about the ones that will matter the most.
And in my opinion, those are the first one is decimal.
So decimal is what it sounds like.
It's a number that includes a decimal afterwards or how can I put this?
I don't think that's the right way of saying it.
It's number that includes a decimal point and something after it, or it can include something after
it.
So when we create a column, we actually provide two arguments and we'll talk about those in just a
moment.
But the important part here is that it's a way of creating a column that will store numbers that include
decimals, something after the decimal point.
So what are these two numbers we're passing in?
Well, on this next slide, I have a handy little graphic here.
When we run or when we create a column, let's say let's call it price.
This is a price of a I don't know, let's work with books.
Our books price.
We have two different arguments.
The first one, five.
Tells my skull the maximum number of digits that our number can have.
So that actually includes both before and after the decimal point.
And then the second number is how many digits come after the decimal point?
So another way of looking at it, something like this.
Here's the maximum number we can store in a decimal five, comma two.
So it's five digits long.
Two of those digits are after the decimal point.
And if we hop over to the documentation, which I'll try and hold my tongue, but I definitely find
to be occasionally subpar, it does an okay job here explaining it.
So the declaration syntax for a decimal column is decimal m comedy m is a maximum number of digits.
The precision it can go up to 65 D is a number of digits to the right of the decimal point also called
the scale.
I have never heard anyone actually use those terms, but I guess it's good to know and it has a range
of 0 to 30, so there can be no more than 30 digits after the decimal point, which in most cases is
going to be plenty.
I mean, way, way, way more than you pretty much ever need.
So that's the gist of decimal here.
It lets us store numbers that have decimals, but we do need to specify roughly what those numbers need
to look like.
So we'll create a very simple table, let's say a generic item.
So items and all we're going to have is a price.
We won't even worry about a name or anything.
So we'll have a column called Price, which is a decimal, and let's go with what we saw there, five
comma two just like that.
So we have that.
Now let's insert a couple of things and test it out.
So insert into items the first one that will do what we need to specify price and then values.
And the first one will be just a whole number, let's say seven.
Just like that.
Then let's do a.
Long whole number like that.
See that we get a warning.
Then let's do 34.88.
Then let's also do a29
8.9999.
And finally, let's do 1.9999.
Okay.
So now let's do our select star from items and see what we have.
So the first thing that you'll notice is when we inserted seven without a decimal, it added those two
decimal places for us.
And again, that's because when we created the table we said there are two places after the decimal,
so it adds those in even if it's a nice whole number.
This next one is a bit weird.
We never inserted 9.99.99.
We inserted 7987654.
So what's happening here is that this is much larger than the maximum number allowed.
The maximum number allowed, as you can see here, is 999.99 because we specified its five digits total
with two coming after the decimal.
So that gives us 999.99.
So good to know when you do this, if you create a number that's too large, it's going to just put
the largest possible decimal.
Given the constraints you set up.
The next step we have our 34.88, which looks just the same.
And then we have 298.9999, which you'll notice here is actually rounded up.
So it's rounded to 299 and that's because we specified rounding to two decimal places.
And when we do that, it's going to round up and that will round up and so on.
Well, actually, it's on this one here.
It will round up to 299.00.
Same thing applies here where we have 1.99999.
So that's the basics of the decimal data type, pretty commonly used.
I'll I'll be using it throughout the course.
With that said, there are other data types that we can use to do the same thing that we're going to
talk about in the next video and we'll discuss why and when you would use each one.