Test: Swift - Floating Point Types
2. let markup = 1.99; var price: Float = 1.0+markup - What’s the price?
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Error
ExplanationThe first constant, markup, is a Double. Since a floating point literal has been assigned during the declaration, Swift will infer it as Double. In the next line of code, price has been declared explicitly as Float. And, it is being assigned a Double value (1.0+markup). There is no implicit type conversion in Swift, and hence, this code will result in an error. If the type of price (Float) is omitted, then this code will work. Swift will assign the type Double to the variable price.
Take the TestTake the complete test on this topic. You will be able to review answers to questions and get a test score.
Take the Test
Question 2 of 5
Test is Based on this Article
More Articles With Similar Tags