WEBVTT

00:00.120 --> 00:06.680
OK so next up in this onslaught of data types we're going to discuss some important numeric types.

00:06.780 --> 00:10.460
So there are quite a few We've already discussed it.

00:10.500 --> 00:12.070
We've used it quite a bit.

00:12.210 --> 00:17.640
It works with whole numbers so it's useful if you're working with things where you need them or want

00:17.640 --> 00:21.320
them to be whole numbers where decimals don't matter.

00:21.330 --> 00:24.420
So we know how it works at this point.

00:24.480 --> 00:29.020
However there are bunch of other data types set my ask to come up with.

00:29.070 --> 00:30.660
We're not going to talk about every single one.

00:30.690 --> 00:33.660
We're just going to talk about the ones that will matter the most.

00:33.660 --> 00:42.270
And in my opinion those are the first one is decimal so decimal is what it sounds like it's a number

00:42.450 --> 00:45.420
that includes a decimal afterwards.

00:45.860 --> 00:48.290
How can I put this thing gets the right way of saying it.

00:48.350 --> 00:51.080
It's a number that includes a decimal point and something after it right.

00:51.080 --> 00:52.740
Can it includes a B after it.

00:52.740 --> 00:57.660
So then we create a column we actually provide two arguments and I'll talk about those in just a moment.

00:57.660 --> 01:04.200
But the important part here is that it's a way of creating a column that will store numbers that include

01:04.200 --> 01:06.630
decimals something after the decimal point.

01:06.630 --> 01:08.880
So what are these two numbers we're passing in.

01:09.150 --> 01:12.660
Well on this next slide I have a handy little graphic here.

01:12.720 --> 01:18.390
When we run or when we create a column let's say let's call it price.

01:18.390 --> 01:20.310
This is a price of a.

01:20.550 --> 01:20.970
I don't know.

01:21.030 --> 01:23.270
Let's work with books or books price.

01:23.670 --> 01:31.760
We have two different arguments the first one five tells my to all the maximum number of digits that

01:31.760 --> 01:32.980
our number can have.

01:33.260 --> 01:40.010
So that actually includes both before and after the decimal point and then the second number is how

01:40.010 --> 01:43.700
many digits come after the decimal point.

01:43.700 --> 01:47.240
So another way of looking at it something like this.

01:47.240 --> 01:51.290
Here's the maximum number we can store in a decimal 5.

01:51.290 --> 01:52.080
Comment too.

01:52.280 --> 01:55.060
So it's five digits long.

01:55.160 --> 01:58.540
Two of those digits are after the decimal point.

01:58.640 --> 02:05.330
And if we hop over to the documentation which I'll try and hold my tongue but I definitely find to be

02:05.330 --> 02:09.600
occasionally subpar it does an OK job here explaining it.

02:09.620 --> 02:16.920
So the declaration syntax for a decimal column is decimal em comedy M is a maximum number of digits

02:16.920 --> 02:20.020
of precision it can go up to 65.

02:20.360 --> 02:23.440
D is a number of digits to the right of the decimal point.

02:23.570 --> 02:30.160
Also called the scale I never heard anyone actually used those terms but I guess it's good to know.

02:30.560 --> 02:38.390
And it has a range of 0 to 30 so there can be no more than 30 digits after the decimal point which in

02:38.390 --> 02:41.230
most cases is going to be plenty.

02:41.260 --> 02:45.450
I mean way way way more than you pretty much ever need.

02:45.590 --> 02:50.700
So that's the gist of decimal here is to store numbers and decimals.

02:50.720 --> 02:55.330
But we do need to specify roughly what those numbers need to look like.

02:55.520 --> 03:02.900
So we'll create a very simple table that say a generic item so items and all we're going to have is

03:02.900 --> 03:03.420
a price.

03:03.430 --> 03:05.390
We don't you worry about a name or anything.

03:05.450 --> 03:08.550
So we'll have a column called price which is a decimal.

03:08.930 --> 03:14.480
And let's go with what we saw there 5 comment too just like that.

03:15.510 --> 03:16.020
OK.

03:16.190 --> 03:16.990
So we have that.

03:17.000 --> 03:19.700
Now let's insert a couple of things and test it out.

03:19.700 --> 03:28.230
So insert into items the first one that will do when you specify price and then values.

03:28.490 --> 03:37.330
And the first one will be just a whole number let's say 7 just like that.

03:37.340 --> 03:55.890
OK then let's do a long number like that see that we get a warning then let's do thirty four point eight

03:56.130 --> 04:05.810
eight and let's also do a two nine eight point nine nine nine nine.

04:06.260 --> 04:12.320
And finally let's do one point nine nine nine nine.

04:12.630 --> 04:17.950
OK so now let's do our Slyke star from items and see what we have.

04:18.420 --> 04:19.130
OK.

04:19.440 --> 04:27.150
So the first thing that you'll notice is when we inserted 7 with our decimal it added those two decimal

04:27.630 --> 04:28.770
places for us.

04:28.770 --> 04:35.220
And again that's because when we created the table we said there are two places after the decimal.

04:35.760 --> 04:38.700
So it adds those in even if it's a nice whole number.

04:38.700 --> 04:40.320
The next one is a bit weird.

04:41.400 --> 04:44.420
We never inserted nine nine nine point nine nine.

04:44.790 --> 04:48.410
We inserted seven nine eight seven six five four.

04:49.020 --> 04:55.050
So what's happening here is that this is much larger than the maximum number allowed the maximum number

04:55.050 --> 04:55.370
allowed.

04:55.380 --> 05:02.820
As you can see here is nine nine nine point nine nine because we specified it's five digits total with

05:02.820 --> 05:04.710
two coming after the decimal.

05:04.710 --> 05:08.010
So that gives just ninety nine point nine nine.

05:08.100 --> 05:10.080
So good to know when you do this.

05:10.170 --> 05:15.260
If you create a number is too large it's going to just put the largest possible decimal.

05:15.270 --> 05:16.950
Given the constraints you set up.

05:17.220 --> 05:22.200
The next step we have our thirty four point eight which looks just the same.

05:23.390 --> 05:26.870
And then we have two nine eight point nine nine nine nine.

05:27.230 --> 05:32.330
Which you'll notice here is actually rounded up so it's rounded to 2 9 9.

05:32.340 --> 05:35.900
And that's because we specified rounding to two decimal places.

05:36.120 --> 05:40.830
And when we do that it's going to round up and that will round up and so on.

05:41.030 --> 05:43.180
Well actually it's on this one here.

05:43.290 --> 05:46.620
It will round up to nine nine point 0 0.

05:46.620 --> 05:50.830
Same thing applies here or we have one point nine nine nine nine.

05:51.180 --> 05:55.820
So that's the basics of the Decimal data type pretty commonly used.

05:55.830 --> 05:58.950
All I'll be using it throughout the course.

05:58.950 --> 06:03.870
With that said there are other data types that we can use to do the same thing that we're going to talk

06:03.870 --> 06:07.570
about in the next video and we'll discuss why and when you would use each one.
