Question: I'm trying to figure out how I can get my program to lose the `.0` after an integer when I don't need the any decimal places.

```
@IBOutlet weak var numberOfPeopleTextField: UITextField!
@IBOutlet weak var amountOfTurkeyLabel: UILabel!
@IBOutlet weak var cookTimeLabel: UILabel!
@IBOutlet weak var thawTimeLabel: UILabel!

var turkeyPerPerson = 1.5
var hours: Int = 0
var minutes = 0.0

func multiply (#a: Double, b: Double) -> Double {
    return a * b
}

func divide (a: Double , b: Double) -> Double {
    return a / b
}

@IBAction func calculateButton(sender: AnyObject) {
    var numberOfPeople = numberOfPeopleTextField.text.toInt()
    var amountOfTurkey = multiply(a: 1.5, b: Double(numberOfPeople!))
    var x: Double = amountOfTurkey
    var b: String = String(format:"%.1f", x)
    amountOfTurkeyLabel.text = "Amount of Turkey: " + b + "lbs"

    var time = multiply(a: 15, b:  amountOfTurkey)
    var x2: Double = time
    var b2: String = String(format:"%.1f", x2)
    if (time >= 60) {
        time = time - 60
        hours = hours + 1
        minutes = time
        var hours2: String = String(hours)
        var minutes2: String = String(format: "%.1f", minutes)

        cookTimeLabel.text = "Cook Time: " + hours2 + " hours and " + minutes2 + " minutes"
    } else {
        cookTimeLabel.text = "Cook Time: " + b2 + "minutes"
    }

}

```

Do I need to make an if statement to somehow turn Double into Int for this to work?

Answer: 
that should work:

```swift
// round your double so that it will be exactly-convertible
if let converted = Int(exactly: double.rounded()) {
  doSomethingWithInteger(converted)
} else {
  // double wasn't convertible for a reason, it probably overflows
  reportAnError("\(double) is not convertible")
}

```

`init(exactly:)` is almost the same with `init(:)`, the only difference is that `init(exactly:)` doesn't crash while `init(:)` may call `fatalError(:)` in case of failure.

You can check their implementations here

* [`init(:)`](https://github.com/apple/swift/blob/master/stdlib/public/core/Integers.swift#L3054)
* [`init(exactly:)`](https://github.com/apple/swift/blob/master/stdlib/public/core/Integers.swift#L3080)
**Swift 4 - Xcode 10**

Use this code to avoid a crash if the double value exceeds the int boundaries (and so isn't representable):

Add this private extension to your class:

```
private extension Int {

    init?(doubleVal: Double) {
        guard (doubleVal <= Double(Int.max).nextDown) && (doubleVal >= Double(Int.min).nextUp) else {
        return nil
    }

    self.init(doubleVal)
}

```

Use the extension in your class this way:

```
func test() {

    let d = Double(123.564)
    guard let intVal = Int(doubleVal: d) else {
        print("cannot be converted")
    }

    print("converted: \(intVal)")
}

```