ACC: Rounding a Number Up or Down by a Desired IncrementLast reviewed: August 29, 1997Article ID: Q155696 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. This article demonstrates how to create a procedure that rounds a number up or down by a specified increment. For example, given the number 3.23, rounding to the nearest .05 results in the number 3.25. The procedure in this article accepts any positive rounding increment as a parameter. In addition to rounding numbers to the nearest fractional amount, you can also round to whole numbers, such as 1, 10, or 100. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0
MORE INFORMATIONThe following example creates a procedure called RoundToNearest, which accepts three parameters:
Parameter Value --------- --------------------------------------------------------- Amt The numeric value you want to round RoundAmt The increment to which Amt will be rounded Direction Constant indicating which direction to round (up or down)For example, RoundToNearest(3.33, 0.1, vb_roundup) returns the value 3.4.
REFERENCESFor more information about rounding, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q97524 TITLE : ACC: Round or Truncate Values to Desired Number of Decimals ARTICLE-ID: Q111781 TITLE : ACC: Rounding Errors Using Floating-Point Numbers |
Additional query words: factor cents dollars quarter dime nickel
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |