Task
In this challenge, you were provided with a variable that was previously defined to have a data type Float
and you were asked to type cast it to a Double
.
Solution
Let’s look at how we should go about this.
-
The first thing is deciding the variable name, which you were told to keep as
newType
. -
As type casting is from
Float
toDouble
when definingnewType
specify the data type asDouble
. -
The last step is simply assigning
newType
the value ofoldType
.
val newType: Double = oldType
You can find the complete solution below:
You were required to write the code on line 2.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy