How to Round a Number in Swift Programming

Rounding is pretty simple in Swift. But as usual there are a few gotchas: 1. Rounding is performed by the rounded() function:

2. If you want to round to a certain number of decimals, try a little arithmetic: