Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>the 4th decimal place is not considerd for the rounding</p> </blockquote> <p>This is not true. </p> <p>According to MSDN, <a href="http://msdn.microsoft.com/en-us/library/3s2d3xkk.aspx" rel="nofollow"><code>Math.Round(decimal)</code></a> uses a rounding type of <a href="http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx" rel="nofollow"><code>MidpointRounding.ToEven</code></a>. </p> <p>The Midpoint Rounding specifies the rounding behavior when the value to be rounded is exactly halfway between the two possible rounded values.</p> <p>For example, </p> <ul> <li><code>0.2649</code> will always round to <code>0.26</code></li> <li><code>0.2651</code> will always round to <code>0.27</code></li> </ul> <p>when rounding to two decimals.</p> <p>What's interesting is what happens in the case of <code>0.2650</code>: by default, using <code>MidpointRounding.ToEven</code> you get:</p> <ul> <li><strong><code>0.26</code></strong> for <code>Math.Round(0.2650, 2)</code></li> <li><code>0.28</code> for <code>Math.Round(0.2750, 2)</code></li> </ul> <p>That's because the rounding is done towards the even most significant digit after rounding (<code>6</code> in the first case, <code>8</code> in the second).</p> <p>If, however, you were to use <code>MidpointRounding.AwayFromZero</code>, you'd get:</p> <ul> <li><code>0.27</code> for <code>Math.Round(0.2650, 2, MidpointRounding.AwayFromZero)</code></li> <li><code>0.28</code> for <code>Math.Round(0.2750, 2, MidpointRounding.AwayFromZero)</code></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload