Desmond
09-26-2003, 10:35 AM
<HTML> <HEAD> <TITLE>Rounding a Number Up or Down</TITLE> </HEAD> <BODY> <h3>Rounding a Number Up or Down</h3> <b>Document ID: IR10018</b> <hr> The information in this article applies to: <ul> <li>AutoPlay Media Studio 5.0 Professional Edition</li> </ul> <hr> <h3>SUMMARY</h3> <p>This article describes how to round numbers up or down using the built in math functions. </p> <h3>DISCUSSION</h3> <p>If you want all fractions to round up (e.g. 2.1 -> 3.0, 2.5 -> 3.0) then use Math.Ceil: </p> <p><code>whole_number = Math.Ceil(decimal_number);</code> </p> <p>If you want all fractions to round down (e.g. 2.1 -> 2.0, 2.5 -> 2.0) then use Math.Floor. </p> <p><code>whole_number = Math.Floor(decimal_number);</code> </p> <p>If you want anything equal to or above ".5" to round up, and anything below ".5" to round down (e.g. 2.1 -> 2.0, 2.5 -> 3.0), use the following calculation: </p> <p><code>n = 2.5; <br> rounded = Math.Floor(n + 0.5);</code> </p> <h3>MORE INFORMATION</h3> <p>For more information please see the following topics in the AutoPlay Media Studio 5.0 help file:</p> <ul> <li><b>Program Reference | Actions | Math | Math.Ceil</b></li> <li><b>Program Reference | Actions | Math | Math.Floor</b></li> </ul> <p> KEYWORDS: AutoPlay Media Studio 5.0, Actions, Math, Round, Whole, Number, Floor, Ceiling </p> <hr> <FONT SIZE=1> Last reviewed: September 26, 2003<br> Copyright © 2003 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br> </FONT> </BODY> </HTML>