Please tell me if this simplified function does what you want:

    f[x_, n_] := Round[x, 10^(1 - n + ⌊ Log10 @ Abs @ x ⌋)] ~SetPrecision~ n

Test:

    Table[f[x*Pi, 4], {x, {1/100, 1/10, 1, 10, 100}}]
    
    % // FullForm

>     {0.03142, 0.3142, 3.142, 31.42, 314.2}
>     
>     List[0.03142`4., 0.3142`4., 3.142`4., 31.42`4., 314.2`4.]