NEW: Master Swift design patterns with my latest book! >>

How to convert an int to a float

Written by Paul Hudson    @twostraws

Swift's Float data type has a built-in constructor that can convert from integers with no extra work from you. For example, to convert the integer 556 into its Float equivalent, you'd use this:

let myInt = 556
let myFloat = Float(myInt)

Available from iOS 7.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Help support Hacking with Swift

This site is funded by Hacking with Swift supporters who buy my e-books. If you can, please support my work – it comes packed with bonus material!

Click here to visit the Hacking with Swift store >>