Let's talk about something that's very, very dangerous, and that is type conversion, it's something
you should avoid, like the plague.
Let's start with a variable called count now, you'd expect a variable called count to just be a number.
However, there are situations like this that arise where you get a number as a string and not a number.
Now, there is a way to actually convert these.
You just say, I want to make an integer out of the variable count.
Right.
And now if I run that, that is going to work perfectly fine.
And if you look over here, one is a string and one is now an integer over on the right side.
So why do I say this is very, very dangerous?
Well, let's have a very bad count.
Let's say you're getting some survey data and by accident, hedgy skips and gets put in, maybe it stands
for six gigabytes of data on the server.
Now, your app doesn't expect that.
So you're going to go integer.
Go ahead and make that into a bad count and watch what happens.
Absolutely nothing until I press the button, apparently we get nil.
Now, what is, Neal, that means there is no value, because when you said I want you to create an
integer from this, the system couldn't physically do it because there's a G in the way.
Right.
So there is no integer as far as it's concerned.
So just puts nothing in now.
There's no error here.
Now, that's that's the tricky thing.
If there was an error, you'd know because the whole thing would crash.
But you're now going to be trying to use Knill where you are using other numbers.
So if you added six to whatever it is, you'd actually be adding zero in the end.
So that's why we want to avoid type conversion.
There are times, like I say, where you have to do it because it's just the way things turn out.
So let's look at the other way where it is fairly safe to do type conversion.
Let's have a var my int equal to whatever seventy eight and let's turn that into a string because we
want to display it on the screen.
Now this.
Is always going to work.
Right, because if you go one way, so you're going from a more general variable, i.e. a no no, you're
going.
Let me get them to go back a second here.
If you're going from a less general variable, i.e., a number onto a more general one is string or,
you know, implicitly that all numbers can be converted to a string.
Everything can be converted to a sentence.
If it's an integer, a float, a double, it doesn't matter.
But you also know that not all strings can be converted to an integer.
So in this first instance, we tried to do strings to integers, which messed up the whole system because
it just doesn't have the capability to create those.
In this case, you can convert every number to a string.
So in this case, the conversion is OK to do right.
And it's actually quite a common one because when we display things on the screens of mobile apps and
various softwares, everything gets turned to a string first before the user can actually see it.
You don't actually print out an integer.
It's always a string.
OK, so that's when it's safe to do and in fact, you know, I'm going to put here.
Unsafe.
And safe now, if you're wondering what these are, these are comments to forward Slash's means, you
can write some stuff that doesn't get interpreted, interpreted by the compiler.
OK, so.
Those are unsafe and safe conversions.
Now, what are we going to do next?
Well, I think I'll set you a little bit of homework.
So what have I got here?
Let's just copy it straight over.
Do do create a double number over 2000 and then print that number to the command line, so you've used
print before, you know how to make a double number, but there's a secret ingredient involving this
lesson that you need to implement to make this work.