Split a double by dot to two numbers

The easiest way would be to first cast the double to a string:

var d = 34.55
var b = "\(d)" // or String(d)

then split the string with the global split function:

var c = split(b) { $0 == "." }   // [34, 55]

You can also bake this functionality into a double:

extension Double {
    func splitAtDecimal() -> [Int] {
        return (split("\(self)") { $0 == "." }).map({
            return String($0).toInt()!
        })
    }
}

This would allow you to do the following:

var number = 34.55
print(number.splitAtDecimal())   // [34, 55]

Well, what you have there is a float, not a string. You can't really "split" it, and remember that a float is not strictly limited to 2 digits after the separator.

One solution is :

var firstHalf = Int(number)
var secondHalf = Int((number - firstHalf) * 100)

It's nasty but it'll do the right thing for your example (it will, however, fail when dealing with numbers that have more than two decimals of precision)

Alternatively, you could convert it into a string and then split that.

var stringified = NSString(format: "%.2f", number)
var parts = stringifed.componentsSeparatedByString(".")

Note that I'm explicitly calling the formatter here, to avoid unwanted behavior of standard float to string conversions.