‫Welcome back.
‫In this video, we are going to have a look at conversion, which means we're going to have a look at
‫implicit and explicit conversion.
‫So let's have a look at explicit conversion first.
‫Therefore, I create a double variable, which I call my double, and I'm going to assign a value of
‫one 1337, for example, and now I'm going to create an integer int my int and this is just going to
‫be nothing.
‫So for now I don't initialize it.
‫So my end doesn't have a value yet.
‫And if I want to put my double value into my integer and cast it into an integer, so let's do that
‫cast double into int or to int, which now will result in that value being stored as an integer.
‫But as you know, integers can only have whole numbers, which means that those additional decimals
‫here will be gone.
‫So let's just have a look at casting.
‫So my int is going to be an integer from my double.
‫So what I do here is I say please make an integer out of the double.
‫And that's what I do with this casting.
‫So that's explicit conversion.
‫So now let's have a look at how this looks like on the console.
‫So right line and I'm going to write my int and finally console.log read.
‫All right so now let's run that and there we are 13 is printed out and as you can see, it's not 13.37,
‫it's 13.
‫That's because it can only contain whole numbers and it just cut off anything behind the decimal point,
‫which means that no matter what, what's stood here, so even if it's 13.9, seven or something like
‫that, it doesn't round the value down or up.
‫It doesn't care.
‫It just cuts it off after the decimal point.
‫All right.
‫So that's explicit conversion.
‫Explicit conversion.
‫And now let's have a look at implicit conversion.
‫So let's put it up here.
‫Implicit conversion, which is, for example, I have a number of type integer and it's a well it's
‫any number.
‫And now I want to store it into my big number.
‫So I'm going to create a very big number and that's just going to be number.
‫So you can do that.
‫You can simply assign a smaller type value.
‫So this means you can simply assign a smaller value of type int into a long you could assign.
‫For example, let's create a float.
‫My float is 13.37 and my new double is going to be my float.
‫So you can do that either with an F or a capital F, you can do that so either from long to int or from
‫double to float, or from other bigger types to smaller types, pretty much.
‫So that's implicit and explicit conversion.
‫And there is something else which is type conversion.
‫So what you also can do is the following.
‫So type conversion.
‫For example, if I want to convert a double type to a string type.
‫So in our case, right line can handle doubles integers, it can handle strings and so forth.
‫But in some other cases you actually need to have a string.
‫So it needs to be a string, for example, to be handled by the method.
‫So in order to make a string out of a double or an integer, you can simply use conversions.
‫And now let's have a look at one.
‫I'm just going to call that string.
‫My string is equal to and now I use my double, which we know is a double value and now I convert it
‫into a string so converts the numeric value of this instance to its equivalent string representation.
‫So what that will do is it will simply convert 13.37 to something like 13.37, but in quotation marks.
‫All right.
‫So that's what we can do.
‫And we can do that with doubles.
‫We can do that with integers.
‫So let's go ahead and use num dot to string to string so you can do that or you could do the same thing
‫with longs and so forth.
‫All right.
‫So pretty much the same principle.
‫Now a little challenge for you.
‫Please go ahead and convert.
‫The float might float into a string as well.
‫All right.
‫I hope you tried it.
‫My float string is equal to my float to string.
‫All right, then.
‫Now let's print it out just to see what that does to my float string.
‫Let's run it.
‫And we get 13.37.
‫Now you can do that even with Booleans.
‫And we haven't covered booleans yet, but booleans are working as follows.
‫So let's have a look at bool and simply create one here.
‫Bool sun is shining.
‫So this is just a variable which can only have two values.
‫So it can either be true or it can be false.
‫So now please go ahead and look outside and see if the sun is shining.
‫And if the sun is shining, then enter true and otherwise enter false.
‫And now what you can do is you can convert the bool sun is shining to a string as well.
‫So you can simply do that and I'm going to save that in string.
‫My bool string is equal to sun shining to string.
‫So now if this variable here and it's called my bool string, so I'm just going to go ahead and call
‫that my bool string and see what it says here.
‫And it says false.
‫As you can see, it should simply print it out.
‫False.
‫So unfortunately, the sun is not shining here in Cologne, Germany, right now.
‫All right.
‫So once again, real quick, we have implicit conversion, which means we convert from one bigger type
‫to a smaller type, which works for numbers.
‫Then we have the explicit conversion which casts, for example, a double to an integer or which can
‫cause a double to a big number or something like that.
‫So to a long then we have type conversion which converts, for example, a double to a string or a flow
‫to a string or any number type to a string.
‫And in the next video, we are going to have a look at parsing where you can see how to parse from a
‫string to a data type, which is a number.
‫So for example, a double, a float, an integer.
‫And that's something that is highly relevant when you, for example, read out information from the
‫user because usually you get this information in sort of a string and you have to convert it into a
‫double or an integer in order to calculate with it or something similar.
‫Great.
‫So see you in the next video.
‫We're going to cover that.