![iOS 12 Programming for Beginners](https://wfqqreader-1252317822.image.myqcloud.com/cover/76/36699076/b_36699076.jpg)
Adding floating-point numbers
Now let's add floating-point numbers, using the let constant, in Playground:
let gradeAvg = 2.9
let version:Float = 1.1
This is demonstrated in the following screenshot:
![](https://epubservercos.yuewen.com/2E52D1/19470383901517806/epubprivate/OEBPS/Images/1dacb3e6-792f-4a7c-a173-b0e9fa59bb20.png?sign=1739280860-BKurMsdFgUxq6FENCWxx9kpgKkidi2cQ-0-fe167f0f0eaad67fb107f4573cf99660)
You will notice that a couple of things are different. First, we are using the let keyword. Using let tells our program that this is a constant. Constants are variables that cannot change once they are set (as opposed to a non-constant variable, which can change after being set).
The other thing you might have noticed is that we explicitly set our version to Float. When dealing with a floating-point number, it can be a Double or a Float. Without getting too technical, a Double is much more precise than a Float. The best way to explain this is to use pi as an example. Pi is a number in which the digits go on forever. Well, we cannot use a number that goes on forever; however, a Double and Float handle how precise that number is. Let's look at the following diagram to see what I mean by precise:
![](https://epubservercos.yuewen.com/2E52D1/19470383901517806/epubprivate/OEBPS/Images/dde8e105-a352-45e2-904d-206e61d2f571.png?sign=1739280860-F9jZm1xP3VzG1oTUlnIsxbaw11m133HQ-0-6b823c65797b895df93592b10363fa66)
So, in the preceding example, you can see that Float only displays 3.14, whereas Double gives you a much more accurate number. In Swift, a Double is preferred. Therefore, if you do not explicitly set the floating-point number to a Float, Swift defaults to a Double. To set version to a Float, you must purposely set it that way.