Let's begin exploring how Swift handles information that's not a string or an integer.
Numbers can also have decimal points, like 3.14 or 9.99. In programming, these are treated differently from integers.
Engagement Message
Have you worked with decimals before?
Numbers with a decimal point are called floating-point numbers. In Swift, the most common type for these is Double
, which provides high precision for decimal calculations.
Examples include 1.0
, 3.14159
, or -2.5
.
Engagement Message
Do you think the value 100
stored without quotes would be a Double?
You can store floating-point numbers in variables just like other types:
You can also perform standard math operations (+
, -
, *
, /
) with Doubles.
Engagement Message
What do you think 1.5 + 2.0
would result in?
