show/hide this revision's text 2 added 9 characters in body; edited body

No, $f$ does not have to be locally constant. Let $a_n$ be a sequence of irrationals that decreases to zero, define $f(x) = 0$ for $x \leq 0$, and let $f(x)$ be a (single) rational number in $(e^{-1/{a_{n+1}}}, e^{-1/{a_n}})$ for $a_{n+1} a_n < x < a_n$a_{n-1}$. Voila!

show/hide this revision's text 1

No, $f$ does not have to be locally constant. Let $a_n$ be a sequence of irrationals that decreases to zero, define $f(x) = 0$ for $x \leq 0$, and let $f(x)$ be a rational number in $(e^{-1/{a_{n+1}}}, e^{-1/{a_n}})$ for $a_{n+1} < x < a_n$. Voila!