Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Jake Adams1,608 Points
There are 2 types of floating points in Swift: Float and Double (both are numbers with decimals)
- Float is a 32-bit representation of a number
- Double is a 64-bit representation
It's important to note that floating points are simply approximations of real numbers. The benefit to floating points is they can represent much larger numbers that an Integer, but they are not without their pitfalls.
For instance, the constant declared below has a value of 1, even though we know it should be more.
let iOnlyEqualOneWTH = Float(1) + Float(0.000000000000001)
As a side note, it's always best to represent currency values using Double as that gives us twice the precision and a much smaller chance of a floating point math error.
Floating point: http://www.webopedia.com/TERM/F/floating_point_number.html