# InfoPath rounding algorithm

Can someone tell me what kind of rounding algorithm is used in InfoPath? Hereby some examples that I see in InfoPath when rounding.

• 0.2245 => 0.224
• 0.2695 => 0.269
• 0.3145 => 0.315

If it was normal rounding, than all numbers would be rounded up because they are ending on a 5.

If it was banker's rounding, it would round to the next even number which is not the case for 0.2695 because 9 is not even.

So I have no clue which algorithm is used to round the numbers.

EDIT 1
I'm using the round function like this to round it on 3 decimals.

``````round({field} * 1000) / 1000
``````

EDIT 2
It's getting even more weird, it makes a difference whether I do a calculation or not.

This

``````round(0.2245 * 1000) / 1000
``````

results in 0.225 like I expect, but this

``````round((0.1525 + 0.072) * 1000) / 1000
``````

results in 0.224 while I would expect it to be 0.225 because 0.1525 + 0.072 is also 0.2245

• Marlou: Which function you are using? Jan 13, 2015 at 15:34
• I edited my post and added the function that I'm using Jan 14, 2015 at 7:57

I think the problem is caused by how InfoPath works internally. It looks like numbers are casted between decimals and doubles and some precision is lost. For example the first number will probably something like 0.22449999999 instead of the 0.2245 it should be and therefor it will be rounded down instead of up.

So I ended up rounding it twice, first on 7 decimals or something so that the number will be 0.2245 again and after that on 3 decimals so it ends up as 0.225. Ugly as hell, but it works :)

To always round a number up, use the round() function. To always round a number down, use the floor() function.

## ROUND function

Rounds a number to a specified number of digits.

Syntax

ROUND(number,num_digits)

Number Is the number you want to round.

Num_digits Specifies the number of digits to which you want to round the number.

Remarks

1. If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal places.

2. If num_digits is 0, then number is rounded to the nearest integer.

3. If num_digits is less than 0, then number is rounded to the left of the decimal point.

## FLOOR function

Rounds number down, toward zero, to the nearest multiple of significance.

Syntax

FLOOR(number,significance)

Number is the numeric value you want to round.

Significance is the multiple to which you want to round.

Remarks

1. If either argument is nonnumeric, FLOOR returns the #VALUE! error value.

2. If number and significance have different signs, FLOOR returns the #NUM! error value.

3. Regardless of the sign of number, a value is rounded down when adjusted away from zero. If number is an exact multiple of significance, no rounding occurs.