Limit a float number to two places after the decimal in Swift

Use a NSNumberFormatterand configure its rounding mode

    let formatter = NumberFormatter()
    formatter.maximumFractionDigits = 2
    formatter.roundingMode = .down
    let s = formatter.string(from: 99.99999)
    print(s as Any) //99.99