{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Test: Swift - Floating Point Types

2. let markup = 1.99; var price: Float = 1.0+markup - What’s the price?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Error
Explanation
The 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 Test
Take 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
icon-swift-article.jpg
This article talks about decimal numbers in Swift, including Float, Double, and CGFloat. Also talks about Binary, Octal, and Hexadecimal representations.
icon-swift-test.jpg
Test on Float and Double types in Swift, as well as binary, octal, and hex representations.

More Articles With Similar Tags
icon-swift-test.jpg
Test on Float and Double types in Swift, as well as binary, octal, and hex representations.
icon-swift-series.jpg
This series of articles goes through the basics of Swift. It introduces Playgrounds and REPL; Variables and Constants; Int, Float, Bool; Tuples, Type Aliases, Type Inference, Type Safety, and more.
icon-swift-article.jpg
Tags: bool, types, swift
This article discusses the boolean types in Swift and contrasts with how these types are used in C and Objective-C.
icon-swift-test.jpg
Tags: bool, types, swift
Test on Boolean Types in Swift.
icon-swift-article.jpg
Tags: int, types, swift
This article goes through the usage of various integer types in Swift (including Int and UInt).
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map