You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »


You can put the relevant expression into a hidden value that represents the integer form of the value.

Round a number down to the nearest integer

If you want to round a number down you can use the int() function to cut off the decimal point (i.e. 2.2 -> 2; 2.7 -> 2)



Round a number up to the nearest integer

Use the following calculation to always round a number up (i.e. 2.2 -> 3; 2.7 -> 3)

If( int(/data/value) < /data/value, int(data/value) + 1, int(/data/value))


This compares whether the decimal form of the lowest integer is smaller than the current value, and if so, rounds up, and otherwise truncates the value. 

Round a number up from .5, otherwise down

As of CommCare 2.19, the "round" function is available. Simply write round(/data/value). Read more here.
You can also use the int() function in combination with multiplying the input by 2, adding 1, and then dividing by 2 (i.e. 2.2 -> 2; 2.7 -> 3)
int ( ( /data/value*2 +1 ) div 2 )

To round to a different number of decimal places, appropriately adjust the constant '2' in the preceding calculation. The constant should be twice the inverse of the desired precision. For example, for a precision of 0.1, constant = 1 / precision * 2 = 1 / 0.1 * 2 = 20. Consequently use int ( ( /data/value*20 +1 ) div 20 ).

Round a number to a certain decimal place

You can use the same principles to round to the nearest .1, .01, .001, etc. with the following formula:

Round to nearest decimal:  round(/data/value*10) div 10

To round to two decimals change the 10's in the formula above to 100. To three decimals change them to 1000, etc.
  • No labels