[Solved] Display only some digits of an Int [closed]


It depends on your specific requirements.

This prints the first two digits of an integer number

let intVal = 12345
print(String(intVal).prefix(2))

Output: 12

Another way which only prints certain ones in the number:

let intVal = 12345
let acceptableValues = ["1", "2"]

let result = String(intVal).filter {
    acceptableValues.contains(String($0))
}
print(result)

Output: 12

solved Display only some digits of an Int [closed]