Thursday, August 11, 2022

[FIXED] How to get top and bottom number of a number in iOS Swift?

Issue

I have a number like 73
how get max and min like 70 and 80.
or 173 I want to get 170 and 180 etc.


Solution

ceil(73/10) * 10 // round up 80
round(73/10) * 10 // round down 70

Playground: enter image description here

EDIT: Here just provide an idea.

let value: Int = 75

func min(_ value: Int) {
    value - value % 10
}

func max(_ value: Int) {
    value + 10 - value % 10
}

min(value)

max(value)


Answered By - William Hu
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.