Rounding Numbers to Two Significant Figures

Viewed 2593

I am sure this is an easy question to any of you are experienced in Swift, however, I just started learning how to program and have no idea where to start. What I am trying to do is a round a number to the nearest whole value, or to the third number. This is what I mean:

12.6 //Want rounded to 13
126 //Want rounded to 130
1264 //Want rounded to 1300

I know swift has a .rounded() function, and I have managed to use it to round the nearest 10th, 100th, etc., however, I cannot round the way I would like to. Any advice would be much appreciated.

3 Answers
Related