Round a value in a set of number

168 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

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