Round up an integer to multiple of 3

integer, rounding, swift

Solution

I got this working in a Playground:

import Foundation

func roundToThree(value: Int) -> Int{
    var fractionNum = Double(value) / 3.0
    let roundedNum = Int(ceil(fractionNum))
    return roundedNum * 3
}

roundToThree(2)
roundToThree(7)

Problem

I would like to round an integer up to its closest multiple of 3. Example: ``` var numberOne = 2 var numberTwo = 7 ``` - numberOne rounded up would equal 3 - numberTwo rounded up would equal 9 I do not want it to ever round down. Any ideas? Thanks

Original source