Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Math.Rounding Question

$
0
0

Hi everyone.  I have a Double that can have any number of points behind the decimal point.  I used Math.Rounding like so:

int Rounding = 2; //The decimal place to round to.

try { MyValue = Math.Round(MyValue, Rounding); } catch { }

Now, my issue here is that if there is less than 2 decimal places, it fails.  I was wondering how it is recommended that I handle that.  I can't seem to figure out how to determine how many places there are behind the decimal place, so I don't know how to handle this.

Also, I wanted to ask which was better,

MyValue = Math.Round(MyValue, Rounding);

or

MyValue = Math.Round(MyValue, Rounding,MidpointRounding.AwayFromZero);

Thanks for your help.

-Matt-


Viewing all articles
Browse latest Browse all 31927

Trending Articles



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