Added a function for calculating the value nearest a specified value.
Added example