1 00:00:00,150 --> 00:00:00,420 Okay. 2 00:00:00,570 --> 00:00:06,450 So next up in this onslaught of data types, we're going to discuss some important numeric types. 3 00:00:06,660 --> 00:00:11,730 So there are quite a few we've already discussed inte we've used it quite a bit. 4 00:00:12,120 --> 00:00:13,890 It works with whole numbers. 5 00:00:13,890 --> 00:00:19,230 So it's useful if you're working with things where you need them or want them to be whole numbers where 6 00:00:19,230 --> 00:00:20,730 decimals don't matter. 7 00:00:21,300 --> 00:00:23,640 So we know how it works at this point. 8 00:00:24,390 --> 00:00:28,870 However, there are a bunch of other data types that MySQL comes with. 9 00:00:28,890 --> 00:00:30,650 We're not going to talk about every single one. 10 00:00:30,660 --> 00:00:33,300 We're just going to talk about the ones that will matter the most. 11 00:00:33,450 --> 00:00:38,280 And in my opinion, those are the first one is decimal. 12 00:00:39,080 --> 00:00:41,540 So decimal is what it sounds like. 13 00:00:41,540 --> 00:00:46,870 It's a number that includes a decimal afterwards or how can I put this? 14 00:00:46,880 --> 00:00:48,260 I don't think that's the right way of saying it. 15 00:00:48,260 --> 00:00:52,430 It's number that includes a decimal point and something after it, or it can include something after 16 00:00:52,430 --> 00:00:52,640 it. 17 00:00:52,640 --> 00:00:57,350 So when we create a column, we actually provide two arguments and we'll talk about those in just a 18 00:00:57,350 --> 00:00:57,680 moment. 19 00:00:57,680 --> 00:01:04,280 But the important part here is that it's a way of creating a column that will store numbers that include 20 00:01:04,280 --> 00:01:06,320 decimals, something after the decimal point. 21 00:01:06,470 --> 00:01:08,900 So what are these two numbers we're passing in? 22 00:01:09,020 --> 00:01:12,410 Well, on this next slide, I have a handy little graphic here. 23 00:01:12,560 --> 00:01:17,870 When we run or when we create a column, let's say let's call it price. 24 00:01:18,290 --> 00:01:22,100 This is a price of a I don't know, let's work with books. 25 00:01:22,100 --> 00:01:23,120 Our books price. 26 00:01:23,510 --> 00:01:25,730 We have two different arguments. 27 00:01:25,730 --> 00:01:26,990 The first one, five. 28 00:01:28,100 --> 00:01:32,960 Tells my skull the maximum number of digits that our number can have. 29 00:01:33,110 --> 00:01:37,430 So that actually includes both before and after the decimal point. 30 00:01:37,940 --> 00:01:42,650 And then the second number is how many digits come after the decimal point? 31 00:01:43,600 --> 00:01:47,200 So another way of looking at it, something like this. 32 00:01:47,200 --> 00:01:52,070 Here's the maximum number we can store in a decimal five, comma two. 33 00:01:52,090 --> 00:01:53,770 So it's five digits long. 34 00:01:55,030 --> 00:01:57,790 Two of those digits are after the decimal point. 35 00:01:58,510 --> 00:02:04,990 And if we hop over to the documentation, which I'll try and hold my tongue, but I definitely find 36 00:02:04,990 --> 00:02:09,449 to be occasionally subpar, it does an okay job here explaining it. 37 00:02:09,460 --> 00:02:16,930 So the declaration syntax for a decimal column is decimal m comedy m is a maximum number of digits. 38 00:02:16,930 --> 00:02:24,160 The precision it can go up to 65 D is a number of digits to the right of the decimal point also called 39 00:02:24,160 --> 00:02:24,940 the scale. 40 00:02:25,210 --> 00:02:31,450 I have never heard anyone actually use those terms, but I guess it's good to know and it has a range 41 00:02:31,450 --> 00:02:39,130 of 0 to 30, so there can be no more than 30 digits after the decimal point, which in most cases is 42 00:02:39,130 --> 00:02:41,110 going to be plenty. 43 00:02:41,110 --> 00:02:45,460 I mean, way, way, way more than you pretty much ever need. 44 00:02:45,460 --> 00:02:48,280 So that's the gist of decimal here. 45 00:02:48,490 --> 00:02:54,550 It lets us store numbers that have decimals, but we do need to specify roughly what those numbers need 46 00:02:54,550 --> 00:02:55,390 to look like. 47 00:02:55,390 --> 00:03:01,150 So we'll create a very simple table, let's say a generic item. 48 00:03:01,150 --> 00:03:03,400 So items and all we're going to have is a price. 49 00:03:03,400 --> 00:03:05,260 We won't even worry about a name or anything. 50 00:03:05,260 --> 00:03:11,200 So we'll have a column called Price, which is a decimal, and let's go with what we saw there, five 51 00:03:11,200 --> 00:03:13,720 comma two just like that. 52 00:03:16,090 --> 00:03:17,020 So we have that. 53 00:03:17,020 --> 00:03:19,510 Now let's insert a couple of things and test it out. 54 00:03:19,510 --> 00:03:28,270 So insert into items the first one that will do what we need to specify price and then values. 55 00:03:28,270 --> 00:03:33,670 And the first one will be just a whole number, let's say seven. 56 00:03:35,720 --> 00:03:36,650 Just like that. 57 00:03:38,540 --> 00:03:40,880 Then let's do a. 58 00:03:42,770 --> 00:03:46,220 Long whole number like that. 59 00:03:48,530 --> 00:03:49,760 See that we get a warning. 60 00:03:50,930 --> 00:03:56,690 Then let's do 34.88. 61 00:03:58,450 --> 00:04:02,140 Then let's also do a29 62 00:04:02,440 --> 00:04:05,470 8.9999. 63 00:04:06,250 --> 00:04:10,840 And finally, let's do 1.9999. 64 00:04:12,490 --> 00:04:13,050 Okay. 65 00:04:13,420 --> 00:04:17,740 So now let's do our select star from items and see what we have. 66 00:04:19,300 --> 00:04:26,860 So the first thing that you'll notice is when we inserted seven without a decimal, it added those two 67 00:04:26,860 --> 00:04:28,710 decimal places for us. 68 00:04:28,720 --> 00:04:34,960 And again, that's because when we created the table we said there are two places after the decimal, 69 00:04:35,620 --> 00:04:38,470 so it adds those in even if it's a nice whole number. 70 00:04:38,620 --> 00:04:40,210 This next one is a bit weird. 71 00:04:41,250 --> 00:04:43,800 We never inserted 9.99.99. 72 00:04:44,670 --> 00:04:48,000 We inserted 7987654. 73 00:04:48,870 --> 00:04:54,100 So what's happening here is that this is much larger than the maximum number allowed. 74 00:04:54,120 --> 00:05:02,610 The maximum number allowed, as you can see here, is 999.99 because we specified its five digits total 75 00:05:02,610 --> 00:05:04,550 with two coming after the decimal. 76 00:05:04,560 --> 00:05:06,810 So that gives us 999.99. 77 00:05:07,980 --> 00:05:13,710 So good to know when you do this, if you create a number that's too large, it's going to just put 78 00:05:13,710 --> 00:05:15,250 the largest possible decimal. 79 00:05:15,270 --> 00:05:16,770 Given the constraints you set up. 80 00:05:17,100 --> 00:05:22,230 The next step we have our 34.88, which looks just the same. 81 00:05:23,330 --> 00:05:29,960 And then we have 298.9999, which you'll notice here is actually rounded up. 82 00:05:30,740 --> 00:05:35,780 So it's rounded to 299 and that's because we specified rounding to two decimal places. 83 00:05:35,930 --> 00:05:40,790 And when we do that, it's going to round up and that will round up and so on. 84 00:05:41,030 --> 00:05:42,860 Well, actually, it's on this one here. 85 00:05:43,310 --> 00:05:46,490 It will round up to 299.00. 86 00:05:46,520 --> 00:05:50,720 Same thing applies here where we have 1.99999. 87 00:05:51,080 --> 00:05:55,750 So that's the basics of the decimal data type, pretty commonly used. 88 00:05:55,760 --> 00:05:58,400 I'll I'll be using it throughout the course. 89 00:05:58,850 --> 00:06:03,740 With that said, there are other data types that we can use to do the same thing that we're going to 90 00:06:03,740 --> 00:06:07,760 talk about in the next video and we'll discuss why and when you would use each one.