Hello and welcome to the fifth tutorial on the swift basics series and in this part we're going to be looking at typecasting, typecasting allows a value or variable to be converted to a particular data type. So, for example, and in Java to float or float to an integer, let's go ahead and open up our project and just show you how to implement this. So we are going to create a variable and call it i equal to nine. print this variable. What we have is the integer nine printed out but perhaps we want to find nine or we want this we want this to be a double. But if we say sign an integer to it initially, we'd still want it to be able to do that you can do one of two things either two colon, double.
Now when you print it out is 9.0. Even though the value nine which is an integer All signed off, and typecasted by Korean, the datatype here and then enclosed in the variable or the value and bracket and then this produces the same without another reason why this is useful if, for example, we do on equals 8.8. Runner it failed because 8.8 isn't an integer and we have nine signed to it initially which makes it an integer, but we can typecast it by putting int bracket, close bracket, run it and now is being typecast it to an int is truncated the number to eight. So typecasting is extremely useful if sometimes you have a few issues with rounding or some mathematical errors. So sometimes typecasting will help so that's it for this tutorial, we'll cover typecasting in the next tutorial we're going to cover how to add variables into strings.
If you have any questions feel free to message your support sonar systems. Korea okay the email in the description. You can comment on this video or directly messaged us via YouTube. The source code from This tutorial will also be in the description and as usual, thanks for watching and have a nice day.