Artificial intelligent assistant

Round a value in a set of number Given an order set of some number, $S=\\{1.3, 1.7, 1.9, 2.8\\}$, I would like to know how can I mathematically define a function that round a value to the nearest number in the set $S$. For example, if I give the value 1.72, I'll receive back the number 1.7.

One possible candidate is $$f(x) = \min \\{\text{arginf}_{y \in S} \vert x-y\vert\\}$$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d7372347e1dffe026ecff5d83f9f4a96