Floating-Point Numbers
To represent a number that has a decimal point, like 3.2, you use a floating-point number. There are two things to bear in mind about floating-point numbers. First, in computers floating-point numbers are stored as a mantissa and an exponent, similar to how you write a number in scientific notation. For example, 123.45 could be stored similarly to 1.2345 x 102 or 12.345 x 101 (although the computer will use base 2 instead of base 10). Additionally, floating-point numbers are often imprecise: There are many numbers that cannot be stored with perfect accuracy in a floating-point number. The computer will store a very close approximation to the number you expect. (More on that in a moment.)
Swift has two basic ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access