O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 as something like 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required