Skip to content

Instantly share code, notes, and snippets.

extension Double {
// Given a value to round and a factor to round to,
// round the value to the nearest multiple of that factor.
mutating func round(toNearest: Double) {
self = (self / toNearest).rounded() * toNearest
}
// Given a value to round and a factor to round to,
// round the value DOWN to the largest previous multiple
// of that factor.