OK 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 it.
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 bunch of other data types set my ask to come up 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.
How can I put this thing gets the right way of saying it.
It's a number that includes a decimal point and something after it right.
Can it includes a B after it.
So then we create a column we actually provide two arguments and I'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 or books price.
We have two different arguments the first one five tells my to all 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 5.
Comment too.
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 OK job here explaining it.
So the declaration syntax for a decimal column is decimal em comedy M is a maximum number of digits
of 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 never heard anyone actually used 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 is to store numbers and decimals.
But we do need to specify roughly what those numbers need to look like.
So we'll create a very simple table that say a generic item so items and all we're going to have is
a price.
We don't you 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 5 comment too just like that.
OK.
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 when you specify price and then values.
And the first one will be just a whole number let's say 7 just like that.
OK then let's do a long number like that see that we get a warning then let's do thirty four point eight
eight and let's also do a two nine eight point nine nine nine nine.
And finally let's do one point nine nine nine nine.
OK so now let's do our Slyke star from items and see what we have.
OK.
So the first thing that you'll notice is when we inserted 7 with our 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.
The next one is a bit weird.
We never inserted nine nine nine point nine nine.
We inserted seven nine eight seven six five four.
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 nine nine nine point nine nine because we specified it's five digits total with
two coming after the decimal.
So that gives just ninety nine point nine nine.
So good to know when you do this.
If you create a number is too large it's going to just put the largest possible decimal.
Given the constraints you set up.
The next step we have our thirty four point eight which looks just the same.
And then we have two nine eight point nine nine nine nine.
Which you'll notice here is actually rounded up so it's rounded to 2 9 9.
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 nine nine point 0 0.
Same thing applies here or we have one point nine nine nine nine.
So that's the basics of the Decimal data type pretty commonly used.
All 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.