Swift Tutorial: Introduction 06 - Variables: Floats and Doubles

Written by Paul Napier on . Posted in Swift Tutorials: Introduction

Hello everyone and welcome to the sixth lesson in swift programming brought to you by MadApper. my name is Paul Napier and in this lesson we will cover another two of the basic types: floats and doubles.

In the last lesson we covered numbers which had nothing after the decimal place. However, if we are going to work with calculations, we are going to constantly face situations where we have decimal places. In these instances we will use either floats or doubles:

let myFloat: Float = 1.025
let myDouble: Double = 1.025

As a definition, floats are floating point numbers which has a 32 bit representation and can have a precision of only 6 decimal places. A double is a floating point number that has a 64 bit representation and a precision of at least 15 decimal places, so when you have large numbers and require a higher degree of accuracy, you should use a double. When declaring these floating point numbers implicitly, the compiler will choose the floating point number most suitable to your system.

So if I type:

let floatingPoint = 1.01

Then start typing floatingPoint again, I can see in the code assistant that the compiler has declared it as a Double. This is important to note and may cause you issues if you did not realise this later on in your code.

Ok, so we have covered off the basics of numbers. In the next lesson we are going to talk briefly about type safety and casting..


0 #15 Coreytax 2018-03-17 16:54
Many thanks, I enjoy it!
cialis generic tadalafil buy cialis pas cher paris generic cialis soft gels cialis 100mg suppliers
prezzo cialis a buon mercato cuanto cuesta cialis yaho we use it cialis online store where to buy cialis in ontario
buy cialis cialis soft tabs for sale
0 #14 2018-02-25 08:18
купить виагру оригинал в москве - купить виагру в москве с доставкой
0 #13 DonnaJew 2018-02-18 09:15
шопинг китайские интернет магазины:
0 #12 Traceeh 2018-01-29 10:42
футболки с симпсонами купить заказать!
Наши товары: одежда, футболки, майки, толстовки, свитшоты, верхняя одежда, шорты, спортивные брюки, одежда для беременных,Популярные майки / Каталог / Кино, мультфильмы и ТВ / Симпсоны и многое другое!
0 #11 gráfica em osasco 2018-01-13 08:17
Ou pior: seus dados estão desatualizados.
0 #10 ReynaldoSmall 2017-11-23 09:07
I have checked your page and i've found some duplicate content, that's why you don't rank
high in google's search results, but there is a tool that can help you to create 100% unique
content, search for; Boorfe's tips unlimited content
0 #9 Roman 2017-11-22 15:36
Congratulations on having Hands dowwn the most sophisticated websites Ive come throughout in many time!
Its just incredible what you can remember from a specific
thing simply because of how visually beautiful its.
Youve put collectively ann awesome website space -great graphics, videos, layout.
That is undoubtedly a must-see weblog!
0 #8 Can a mean P. 2017-10-02 10:11
Are you looking for acadmic help?
don't worry we provided professional service of this.

visit here and tell us your work.
0 #7 The Word Point 2017-09-30 02:44
It has not till hell freezes over been easier to judge
between the interpretation services, as all consumer opinions and testimonials
are gathered in anyone see fitted you to pick the best.
Bolt awful je sais quoi and as a culminate inadequate familiarity by means
of consulting any rewording website reviews.
Utterly written testimonials purpose manual you through the dispose
of of selecting the united and purely transfiguration checking that last
will and testament fit your needs.
0 #6 arabic translation 2017-09-28 08:28
Businesses are erasing the boundaries between nations and as a result,
communication with the chief part in expanding your reach as entrepreneur.
Communication, in this matter, is the knack to spell out between any lingua franca pair there is
and the transfer services explode has made it steady
easier. You valid have to persuade unwavering the flock you trust your transference
offers objective accommodation, which can be verified by checking the reviews of the fastidious

Add comment

Security code