I'm using XLSForm. Is there a way to constrain a decimal input field to

only accept increments of 0.5? So, a valid input would be 2.0 or 2.5 but

not 2.75. I'd rather not use calculate to round the decimal (the field that

I'm trying to constrain is collecting the number of stories in a building

and only whole or half stories are possible).

Thanks!

Hi Ed,

You might be able to use the "mod" operator. For example, try something

like this in your constraint column:

(${floors} mod 0.5) < 0.01 (the 0.01 is to avoid floating point rounding

errors)

However, I've never tested the mod operator in Collect, much less with

decimal values, so I'm not sure if that approach will work.

If it doesn't you can accomplish the same thing with the div operator and

round/int function:

(${floors} div 0.5) - int(${floors} div 0.5) < 0.01

Regards,

-Nathan

## ···

On Saturday, May 11, 2013 9:45:43 AM UTC-7, Ed FitzGerald wrote:
>
> I'm using XLSForm. Is there a way to constrain a decimal input field to
> only accept increments of 0.5? So, a valid input would be 2.0 or 2.5 but
> not 2.75. I'd rather not use calculate to round the decimal (the field that
> I'm trying to constrain is collecting the number of stories in a building
> and only whole or half stories are possible).
>
> Thanks!
>

Thanks for your help Nathan! "Mod" seems to be working in Enketo. I'll test

it out on a device when I get a chance.

## ···

On Saturday, May 11, 2013 11:47:52 PM UTC-5, Nathan wrote:
>
> Hi Ed,
> You might be able to use the "mod" operator. For example, try something
> like this in your constraint column:
> (${floors} mod 0.5) < 0.01 (the 0.01 is to avoid floating point rounding
> errors)
> However, I've never tested the mod operator in Collect, much less with
> decimal values, so I'm not sure if that approach will work.
> If it doesn't you can accomplish the same thing with the div operator and
> round/int function:
> (${floors} div 0.5) - int(${floors} div 0.5) < 0.01
> Regards,
> -Nathan
>
> On Saturday, May 11, 2013 9:45:43 AM UTC-7, Ed FitzGerald wrote:
>>
>> I'm using XLSForm. Is there a way to constrain a decimal input field to
>> only accept increments of 0.5? So, a valid input would be 2.0 or 2.5 but
>> not 2.75. I'd rather not use calculate to round the decimal (the field that
>> I'm trying to constrain is collecting the number of stories in a building
>> and only whole or half stories are possible).
>>
>> Thanks!
>>
>

Ed,

If the mod trick fails, you can also use regex to match the input.

I haven't tested this extensively, but this should work: +.[0,5]$

Yaw

## ···

--
Need ODK help? Go to http://nafundi.com for custom features, form
design, implementation support, and user training for ODK.
On Sun, May 12, 2013 at 8:25 AM, Ed FitzGerald fitzed@gmail.com wrote:

Thanks for your help Nathan! "Mod" seems to be working in Enketo. I'll test

it out on a device when I get a chance.

On Saturday, May 11, 2013 11:47:52 PM UTC-5, Nathan wrote:

Hi Ed,

You might be able to use the "mod" operator. For example, try something

like this in your constraint column:

(${floors} mod 0.5) < 0.01 (the 0.01 is to avoid floating point rounding

errors)

However, I've never tested the mod operator in Collect, much less with

decimal values, so I'm not sure if that approach will work.

If it doesn't you can accomplish the same thing with the div operator and

round/int function:

(${floors} div 0.5) - int(${floors} div 0.5) < 0.01

Regards,

-Nathan

On Saturday, May 11, 2013 9:45:43 AM UTC-7, Ed FitzGerald wrote:

I'm using XLSForm. Is there a way to constrain a decimal input field to

only accept increments of 0.5? So, a valid input would be 2.0 or 2.5 but not

2.75. I'd rather not use calculate to round the decimal (the field that I'm

trying to constrain is collecting the number of stories in a building and

only whole or half stories are possible).

Thanks!

## --

Post: opendatakit@googlegroups.com

Unsubscribe: opendatakit+unsubscribe@googlegroups.com

Options: http://groups.google.com/group/opendatakit?hl=en

You received this message because you are subscribed to the Google Groups

"ODK Community" group.

To unsubscribe from this group and stop receiving emails from it, send an

email to opendatakit+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.