# Display a calculation to 2 decimal places

Hi,

Im trying to display the answer to a BMI calculation, but I only want it to
2 decimal places, otherwise the long list of decimals can be confusing.

ie. “Mother’s BMI is <output…>”

I can only find on the help pages how to round to a whole number. Is there
a way of doing this for 2 decimal places?

Thanks

Natasha

Hi Natasha,

Please take a look at the final paragraph of the Rounding Numbers
https://confluence.dimagi.com/display/commcarepublic/Common+Logic+and+Calculations#CommonLogicandCalculations-Roundingnumbers
section
of the logic and calculations page.

Thanks,
Will

··· On Mon, Dec 8, 2014 at 3:02 AM, Natasha Lelijveld < natasha.lelijveld@gmail.com> wrote:

Hi,

Im trying to display the answer to a BMI calculation, but I only want it
to 2 decimal places, otherwise the long list of decimals can be confusing.

ie. “Mother’s BMI is <output…>”

I can only find on the help pages how to round to a whole number. Is there
a way of doing this for 2 decimal places?

Thanks

Natasha

You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an

Hi Will,

thanks.

I was trying to follow those instructions :

For example, for a precision of 0.1, constant = 1 / precision * 2 = 1 / 0.1

• 2 = 20. Consequently use int ( ( /data/value20 +1 ) div 20 )*.

But I thought because the logic has “int” at the start, doesn’t this mean
it will just come back with a whole number?

Hi Natasha,

I believe that formula is slightly wrong. The div 20 should be outside the
int() expression. It should be:

int ( /data/value20 +1 ) div 20 *

I updated the help site accordingly.

Regards,
Nick

Nick Nestle
Project Manager | Dimagi South Africa
+27 79 439 6081

··· On Tue, Dec 9, 2014 at 9:58 AM, Natasha Lelijveld < natasha.lelijveld@gmail.com> wrote:

Hi Will,

thanks.

I was trying to follow those instructions :

For example, for a precision of 0.1, constant = 1 / precision * 2 = 1 /
0.1 * 2 = 20. Consequently use int ( ( /data/value20 +1 ) div 20 )*.

But I thought because the logic has “int” at the start, doesn’t this mean
it will just come back with a whole number?

You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an

Hi Natasha,

sorry, to correct myself, that example was to round to the nearest .5. I
added a section for rounding to certain decimal places (and pasting below
here):

··· =============

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: * int(/data/value10 + .5) 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.

Nick Nestle
Project Manager | Dimagi South Africa
+27 79 439 6081

On Tue, Dec 9, 2014 at 10:09 AM, Nick Nestle nnestle@dimagi.com wrote:

Hi Natasha,

I believe that formula is slightly wrong. The div 20 should be outside
the int() expression. It should be:

int ( /data/value20 +1 ) div 20 *

I updated the help site accordingly.

Regards,
Nick

Nick Nestle
Project Manager | Dimagi South Africa
+27 79 439 6081

On Tue, Dec 9, 2014 at 9:58 AM, Natasha Lelijveld < natasha.lelijveld@gmail.com> wrote:

Hi Will,

thanks.

I was trying to follow those instructions :

For example, for a precision of 0.1, constant = 1 / precision * 2 = 1 /
0.1 * 2 = 20. Consequently use int ( ( /data/value20 +1 ) div 20 )*.

But I thought because the logic has “int” at the start, doesn’t this mean
it will just come back with a whole number?

You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an