Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Follow these links for the MSDN descriptions of:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.math.floor.aspx" rel="noreferrer"><code>Math.Floor</code></a>, which rounds down towards negative infinity.</li> <li><a href="http://msdn.microsoft.com/en-us/library/system.math.ceiling.aspx" rel="noreferrer"><code>Math.Ceiling</code></a>, which rounds up towards positive infinity.</li> <li><a href="http://msdn.microsoft.com/en-us/library/system.math.truncate.aspx" rel="noreferrer"><code>Math.Truncate</code></a>, which rounds up or down towards zero.</li> <li><a href="http://msdn.microsoft.com/en-us/library/system.math.round.aspx" rel="noreferrer"><code>Math.Round</code></a>, which rounds to the nearest integer or specified number of decimal places. You can specify the behavior if it's exactly equidistant between two possibilities, such as rounding so that the final digit is even ("<code>Round(2.5,MidpointRounding.ToEven)</code>" becoming 2) or so that it's further away from zero ("<code>Round(2.5,MidpointRounding.AwayFromZero)</code>" becoming 3).</li> </ul> <p>The following diagram and table may help:</p> <pre><code>-3 -2 -1 0 1 2 3 +--|------+---------+----|----+--|------+----|----+-------|-+ a b c d e a=-2.7 b=-0.5 c=0.3 d=1.5 e=2.8 ====== ====== ===== ===== ===== Floor -3 -1 0 1 2 Ceiling -2 0 1 2 3 Truncate -2 0 0 1 2 Round (ToEven) -3 0 0 2 3 Round (AwayFromZero) -3 -1 0 2 3 </code></pre> <p>Note that <code>Round</code> is a lot more powerful than it seems, simply because it can round to a specific number of decimal places. All the others round to zero decimals always. For example:</p> <pre><code>n = 3.145; a = System.Math.Round (n, 2, MidpointRounding.ToEven); // 3.14 b = System.Math.Round (n, 2, MidpointRounding.AwayFromZero); // 3.15 </code></pre> <p>With the other functions, you have to use multiply/divide trickery to achieve the same effect:</p> <pre><code>c = System.Math.Truncate (n * 100) / 100; // 3.14 d = System.Math.Ceiling (n * 100) / 100; // 3.15 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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