Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

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

$
0
0

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,


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>