Unofficial Content
  • This documentation is valid for:

Rounds to even the value of a given numeric expression.

Syntax

RoundToEven(nExp1 , nCte)

Type Returned

Numeric.

Where:

nExp1
Must be a Numeric Expression.

nCte
Must be a Numeric Constant

Description

This function is different from round. The return value is the number closest to the value of expression, with the appropriate number of decimal places. If expression is exactly halfway between two possible rounded values, the function returns the possible rounded value whose rightmost digit is an even number. (In a round function, also known as round to larger, a number that is halfway between two possible rounded values is always rounded to the larger number.)
If nCte is a negative number, the Round function apply to the integer part of the number.

Notes
Round to even is a statistically more accurate rounding algorithm than round.
The round to even is use to a better distribution of the global results in some calculations.

Example

  • ROUNDTOEVEN(1.5, 0) = 2 (Round(1.5, 0) = 2)
  • ROUNDTOEVEN(2.5, 0) = 2 (Round(2.5, 0) = 3)
  • ROUNDTOEVEN(2.51, 0) = 3 (Round(2.51, 0) = 3)
  • ROUNDTOEVEN(1.25, 1) = 1.2 (Round(1.25, 1) = 1.3)
  • ROUNDTOEVEN(1.24, 1) = 1.2 (Round(1.24, 1) = 1.2)
  • ROUNDTOEVEN(125.11, -1) = 120 (Round(125.11, -1) = 130)
  • ROUNDTOEVEN(135.11, -1) = 140 (Round(135.11, -1) = 140)

&sum = 145
&count = 10
&avg = ROUNDTOEVEN( &sum / &count , 0)
Result: &avg = 14 (Round( &sum / &count , 0) = 15)

Scope

Languages: Java, .NET, .NET Mobile, Visual Basic
Objects: Procedures, Reports, Transactions, Web Panels, Work Panels
Interfaces: Win, Web

See Also

MSDN
Math world

 

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant