Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Types Numbers and Booleans

Gregory Millan
Gregory Millan
3,719 Points

Doubles and Floats...When to use them?

From my understanding of the video i thought Floats were supposed to be the type if the decimal number was 7 digits or less and Double when its 15 or less.

I tried to list the 9.99 as a Float type in the quiz but I was wrong, can any body help me

1 Answer

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

Double is used by default in Swift, and is also more precise than float. Float demand less of the CPU, but it's not really noticeable on a modern device. It's almost always better to use double, however, for financial software, neither double nor float is precise enough, but that's a more complicated story.

Gregory Millan
Gregory Millan
3,719 Points

You brought some understanding of the subject to me but I still don't understand the decimal place part. Outside of swift if I'm dealing with smaller numbers or numbers with less decimal places should I use Float?

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

There is no such generalization. Different programming languages may work a little bit differently. Some even have a third option named decimal. Generally, a float is 32-bit while a double is 64-bit. Sure, you could use a float for smaller numbers, but there's rarely a reason to do so. Again, it's almost always better to use double.