+ 1

How to round in Swift?

I am trying to do the Halloween candy code coach challenge. I'm almost there but can't figure out how to round the final answer up. Googling has shown me multiple different ways to supposedly round in Swift, but most weren't working for me. I finally found myVariable.rounded() to work, but this only rounds in the traditional way. I need a function that will always round up. Any idea how I do this?

4th Sep 2020, 5:51 PM
Michelle
Michelle - avatar
1 Antwort
+ 6
Append .rounded(.up) to the number, parentheses surrounded calculation, or variable etc. 3.14.rounded(.up) (10.0 / 3.0).rounded(.up) let total = 9.9 total.rounded(.up)
4th Sep 2020, 6:59 PM
ChaoticDawg
ChaoticDawg - avatar