Skip to main content
1 of 2
Gymhgy
  • 8k
  • 13
  • 35

C# (Visual C# Interactive Compiler), 283 bytes

c=>{int d=c.IndexOf('.');int t=c.IndexOfAny(new char[]{'8','9','0','1'},1);var z=decimal.Parse(c);Func<decimal>q=()=>(decimal)Math.Pow(10,c[0]=='8'||c[0]=='9'?d<0?c.Length:d:d<0?c.Length-t:d>t?d-t:d-t+1);return c[0]=='8'||c[0]=='9'?Math.Round(z/q())*q():t<0?z:Math.Round(z/q())*q();} 

It can be shorter if I used doubles instead of decimals, but I used decimals to preserve accuracy, or else a number like 547.4726 would be 547.472595214844.

Try it online!

Try it online!(Doubles Version, 271 bytes)

Gymhgy
  • 8k
  • 13
  • 35