get value in between 5% of the result

hello

i am a beginner in arduino programming
i have searched/google this problem but can not find solution

my question is

i was measuring a voltage from LM317 output voltage
i have managed digitally controlling the pot to set a desire voltage
but yet its hard to get precise voltage that i have set

let say i set 5.2V in my code
the digital pot start running up from 1.25V to 32V

 if (mVolt < setVolt) {
      clockwise(1, 1);
 } 
    
if (mVolt > setVolt) {
     anticlockwise(1, 1);
 }

where mVolt is the reading of the voltage value
anticlockwise and clockwise is the turning of the pot direction

but the pot keep running backward and forward trying to get a matched 5.2V i have set which is impossible to get precise measurement

so please anybody assist me a code
how to make it stop turing the pot if its already reached +/- 5% from the desire voltage set

Google hysteresis or search the forum for examples

you require some hysteresis to prevent the system switching on/off around the set point,e.g. below 5.1 volts switch on above5.3volts swich off

if (mVolt < 5100) {
      clockwise(1, 1);
 }
   
if (mVolt > 5300) {
     anticlockwise(1, 1);
 }

owh i see
let me try to code it