locked
Math.Round produces different results depending on where it is run RRS feed

  • Question

  • I have the following line of code that is producing 2 different results.  

    Given the following line

    var rounded = Math.Round(415 *0.01f, 1);

    I would expect this to round to 4.2 all the time.  When I run this from a console application I always get the expected result 4.2.  If I put the same line in a unit test and run that test I end up with 4.1.  I also end up with 4.1 if the line is running in a windows service.

    Any thoughts as to why it would produce a different value or how to make it behave consistently?

    Running this with visual studio 2013 on a 64 bit machine with .NET 4.5.

    Thanks,

    Friday, July 31, 2015 1:35 AM

Answers