1 00:00:00,540 --> 00:00:07,800 Let's talk about something that's very, very dangerous, and that is type conversion, it's something 2 00:00:07,800 --> 00:00:09,900 you should avoid, like the plague. 3 00:00:11,260 --> 00:00:17,680 Let's start with a variable called count now, you'd expect a variable called count to just be a number. 4 00:00:18,520 --> 00:00:26,020 However, there are situations like this that arise where you get a number as a string and not a number. 5 00:00:27,010 --> 00:00:29,410 Now, there is a way to actually convert these. 6 00:00:29,530 --> 00:00:34,170 You just say, I want to make an integer out of the variable count. 7 00:00:35,050 --> 00:00:35,380 Right. 8 00:00:35,560 --> 00:00:38,800 And now if I run that, that is going to work perfectly fine. 9 00:00:38,800 --> 00:00:44,080 And if you look over here, one is a string and one is now an integer over on the right side. 10 00:00:45,610 --> 00:00:49,520 So why do I say this is very, very dangerous? 11 00:00:49,540 --> 00:00:52,030 Well, let's have a very bad count. 12 00:00:53,640 --> 00:01:01,500 Let's say you're getting some survey data and by accident, hedgy skips and gets put in, maybe it stands 13 00:01:01,500 --> 00:01:04,210 for six gigabytes of data on the server. 14 00:01:04,740 --> 00:01:06,390 Now, your app doesn't expect that. 15 00:01:06,630 --> 00:01:08,490 So you're going to go integer. 16 00:01:09,470 --> 00:01:12,950 Go ahead and make that into a bad count and watch what happens. 17 00:01:15,510 --> 00:01:19,800 Absolutely nothing until I press the button, apparently we get nil. 18 00:01:20,870 --> 00:01:25,970 Now, what is, Neal, that means there is no value, because when you said I want you to create an 19 00:01:25,970 --> 00:01:29,900 integer from this, the system couldn't physically do it because there's a G in the way. 20 00:01:30,170 --> 00:01:30,570 Right. 21 00:01:30,620 --> 00:01:32,650 So there is no integer as far as it's concerned. 22 00:01:32,960 --> 00:01:35,090 So just puts nothing in now. 23 00:01:35,120 --> 00:01:36,050 There's no error here. 24 00:01:36,620 --> 00:01:38,390 Now, that's that's the tricky thing. 25 00:01:38,540 --> 00:01:41,180 If there was an error, you'd know because the whole thing would crash. 26 00:01:41,690 --> 00:01:46,960 But you're now going to be trying to use Knill where you are using other numbers. 27 00:01:47,300 --> 00:01:52,640 So if you added six to whatever it is, you'd actually be adding zero in the end. 28 00:01:54,560 --> 00:01:57,410 So that's why we want to avoid type conversion. 29 00:01:57,440 --> 00:02:01,820 There are times, like I say, where you have to do it because it's just the way things turn out. 30 00:02:02,750 --> 00:02:07,710 So let's look at the other way where it is fairly safe to do type conversion. 31 00:02:08,060 --> 00:02:17,020 Let's have a var my int equal to whatever seventy eight and let's turn that into a string because we 32 00:02:17,180 --> 00:02:18,620 want to display it on the screen. 33 00:02:19,400 --> 00:02:20,360 Now this. 34 00:02:21,770 --> 00:02:23,590 Is always going to work. 35 00:02:24,860 --> 00:02:34,340 Right, because if you go one way, so you're going from a more general variable, i.e. a no no, you're 36 00:02:34,340 --> 00:02:34,610 going. 37 00:02:34,910 --> 00:02:37,190 Let me get them to go back a second here. 38 00:02:37,520 --> 00:02:44,480 If you're going from a less general variable, i.e., a number onto a more general one is string or, 39 00:02:44,480 --> 00:02:48,120 you know, implicitly that all numbers can be converted to a string. 40 00:02:48,530 --> 00:02:50,960 Everything can be converted to a sentence. 41 00:02:51,170 --> 00:02:53,840 If it's an integer, a float, a double, it doesn't matter. 42 00:02:54,770 --> 00:03:01,080 But you also know that not all strings can be converted to an integer. 43 00:03:02,030 --> 00:03:09,530 So in this first instance, we tried to do strings to integers, which messed up the whole system because 44 00:03:09,530 --> 00:03:12,350 it just doesn't have the capability to create those. 45 00:03:13,220 --> 00:03:16,580 In this case, you can convert every number to a string. 46 00:03:16,910 --> 00:03:21,480 So in this case, the conversion is OK to do right. 47 00:03:21,800 --> 00:03:26,390 And it's actually quite a common one because when we display things on the screens of mobile apps and 48 00:03:26,390 --> 00:03:31,360 various softwares, everything gets turned to a string first before the user can actually see it. 49 00:03:31,730 --> 00:03:33,970 You don't actually print out an integer. 50 00:03:33,980 --> 00:03:34,880 It's always a string. 51 00:03:36,250 --> 00:03:40,000 OK, so that's when it's safe to do and in fact, you know, I'm going to put here. 52 00:03:41,510 --> 00:03:42,350 Unsafe. 53 00:03:43,490 --> 00:03:49,490 And safe now, if you're wondering what these are, these are comments to forward Slash's means, you 54 00:03:49,490 --> 00:03:54,170 can write some stuff that doesn't get interpreted, interpreted by the compiler. 55 00:03:55,100 --> 00:03:55,880 OK, so. 56 00:03:56,970 --> 00:03:59,430 Those are unsafe and safe conversions. 57 00:04:01,340 --> 00:04:03,620 Now, what are we going to do next? 58 00:04:03,650 --> 00:04:05,460 Well, I think I'll set you a little bit of homework. 59 00:04:05,480 --> 00:04:06,470 So what have I got here? 60 00:04:06,560 --> 00:04:08,360 Let's just copy it straight over. 61 00:04:11,620 --> 00:04:20,050 Do do create a double number over 2000 and then print that number to the command line, so you've used 62 00:04:20,050 --> 00:04:25,720 print before, you know how to make a double number, but there's a secret ingredient involving this 63 00:04:25,720 --> 00:04:28,770 lesson that you need to implement to make this work.