Behavior of Math.Round

Asked

Viewed 45 times

3

I have a project in VB.Net that I use the Round Function, but see the strange behavior:

System.Console.WriteLine(math.round(32.625,2)) '32.62
System.Console.WriteLine(math.round(32.635,2)) '32.64
System.Console.WriteLine(math.round(32.645,2)) '32.65

system.console.writeLine(math.round(21.525,2)) '21.52
System.Console.WriteLine(math.round(21.535,2)) '21.54
System.Console.WriteLine(math.round(21.545,2)) '21.54

Does anyone know why?

  • 3

    The fault lies in the inaccuracy of the Doubles. https://docs.microsoft.com/en-us/dotnet/api/system.math.round?view=netframework-4.7.2#rounding-and-Precision

  • 1

    This 32,635 internally equals 32,634998321533203125. https://stackoverflow.com/questions/14835001/what-is-wrong-with-math-round-in-vb-net https://stackoverflow.com/questions/3969674/net-rounding-issue

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.