[swift] Rounding a double value to x number of decimal places in swift

Here's one for SwiftUI if you need a Text element with the number value.

struct RoundedDigitText : View {
    let digits : Int
    let number : Double

    var body : some View {
        Text(String(format: "%.\(digits)f", number))
    }
}