# Use FLOOR to assign condition based on participant number

5 years 11 months ago #96611
Dear readers, I am having a problem with the following. In my survey, I assign people to condition based on their participant number, using the FLOOR function. However, some numbers are SKIPPED completely, and I can't pinpoint the error. Here is the process I use:

Participants' number is filled in in a question called 'ppno'
The next question is equation type, called 'condition'. The equation is {((((ppno/3)-(FLOOR(ppno/3)))*3)}

Then there are 3 questions, each of which is a different condition of my experimental manipulation. The questions have these relevance equations:

condition == 0
condition == 1
condition == 2

Now, when I entered participant number 211, I first noticed the problem that it SKIPS these questions completely. Yet I don't see how the outcome of ((((211/3) - (floor(211/3)))*3) could be anything other than 0|1|2

Could anyone point me in the right direction please? I've been at this for 3 hours and it seems like it should be simple!

Thank you so much,
Caspar

LimeSurvey Partners
5 years 11 months ago - 5 years 11 months ago #96636 by tpartner
Yeah, that should equal 1 but I think you have an extra bracket. Try this:
`{(((ppno/3) - (floor(ppno/3))) * 3)}`

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 5 years 11 months ago by tpartner.

5 years 11 months ago #96664
Thanks for your response tpartner! Unfortunately, the way you wrote it up is exactly like it is in my actual survey. I mistyped it in my original post.

To be clear: the problem is not that this code NEVER works, the problem is that the code doesn't work for SOME values of ppno. The first time the code failed me is when using ppno = 211. The problem is consistent, i.e. it NEVER works with ppno = 211, and I've since then discovered it also fails with some other numbers.

Any idea how it could be that the code fails only for some values of 'ppno'?

5 years 11 months ago #96679 by tpartner
Try this to make sure you get a whole number as a result:
`{ceil(((ppno/3) - (floor(ppno/3))) * 3)}`

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: cjvanlissa

5 years 11 months ago #96681
Ace! That did the trick! Thanks you for your help

5 years 11 months ago #96711
Actually, still not working. It worked for 211, but a different ppno (95) still resulted in the questionnaire skipping the conditional questions.

This is really bizarre; the code has been working perfectly for months, and now suddenly it results in major issues. Even updating Limesurvey did not make a difference.

5 years 11 months ago #96714 by tpartner
I get exactly 3 with a ppno of 95.

Try putting something like this in a text-display question to see the equation component values:
```ppno/3: {(ppno.shown/3)}
floor(ppno/3): {floor(ppno.shown/3)}
(ppno/3) - (floor(ppno/3): {((ppno.shown/3) - (floor(ppno.shown/3)))}
ceil(((ppno/3) - (floor(ppno/3))) * 3): {ceil(((ppno.shown/3) - (floor(ppno.shown/3))) * 3)}```

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com