Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Rounding the display of a calculated mean score (Equation)

  • Feorod
  • Feorod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 months ago #193053 by Feorod
Hi all,

Technical question. I calculate a MEAN in an EQUATION question. The mean consists of the SUM of all valid scores on a serie of similar scaled items (1 to 4 scale) DIVIDED by the number of valid items ("Do not apply" is possible in the scale).

My question is about the display of the MEAN result at the end of the survey and anywhere this variable is called after, i.e. Simple notification email.

LS displays the full mean with 10 decimals (ex: 3.3451324232) but I would like to display or round to the 2nd decimal (ex: 3.35).

I tried with "{round(mean.NAOK,2)}" with no success, LS displayed "0".

The MEAN is named MOYENNE (in french) in the attachment jpg.

If there is a quicker/easier way to proceed, please do reply !

Thanx,

Eric
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 months ago #193054 by Joffm
Use the normal old fashioned way:

round(mean*100)/100

round(3.3451324232*100)/100
= round(334.51324232)/100
= 335/100
= 3.35

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • Feorod
  • Feorod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 months ago #193056 by Feorod
Hey Joff,

I would if I could :) The devil is in the details. Here is the syntax of the ROUND function in LS Manual - Expression Manager:

round Rounds a number to an optional precision number round(val [, precision])

My question is HOW to write correctly the ROUND syntax in order to display the calculated MEAN with 2 decimals. First, is it possible to enter a variable inside the function ("val") ? If so, what suffix is valid (.NAOK, .shown or .value) ??? Second, the manual reads "number round" in the syntax format... weird, is the syntax ROUND or NUMBER ROUND ?

Inserting {round(MEAN.naok,2)} in the Notification email returned a displayed value of "0".

Thanx for your reply,

Eric
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 months ago #193057 by Joffm
I do not see an issue
Sum: {sum(Q0_SQ001.NAOK,Q0_SQ002.NAOK,Q0_SQ003.NAOK)}

Mean:{sum(Q0_SQ001.NAOK,Q0_SQ002.NAOK,Q0_SQ003.NAOK)/3}

Mean2: {round(sum(Q0_SQ001.NAOK,Q0_SQ002.NAOK,Q0_SQ003.NAOK)/3,2)}



And your syntax {round(MEAN.naok,2)} is wrong.
MEAN is not a question, so no NAOK. And NAOK in capital letters.
manual.limesurvey.org/Expression_Manager...#Access_to_variables

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • Feorod
  • Feorod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 months ago #193058 by Feorod
Joff,

You are exactly right. But in my survey MEAN is in fact an Equation question.

I understand now what my bug was. I typed descriptive text into the Equation so the output value was a mix of text and numbers. No wonder the ROUND didn't work... My bad.

Thanx a lot for your precisions, it's all noted :)

Eric
The topic has been locked.
More
4 years 2 months ago #193060 by jelo

Joffm wrote: MEAN is not a question, so no NAOK.

Are you aware of any constellation wher NAOK is causing problems. NAOK is often used everywhere even if it makes no sense. But that is mostly to be on the safe side ;-)

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 months ago #193061 by Joffm

MEAN is in fact an Equation question.

Of course it is.
But it is already a calculated value, so NAOK is obsolete.
NAOK is used in calculations like "sum(Q1,Q2,Q3)" which would not be calculated if one of the arguments is "no answer". Therefore "sum(Q1.NAOK,Q2.NAOK,Q3.NAOK)"

And now I saw that MEAN.naok only was a typo.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Feorod
  • Feorod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 months ago #193087 by Feorod
Joff,

I must admit this suffix thing is VERY confusing. The LS Manual (Expression manager) is not clear about when or why using this or that suffix in equations and in displaying values inside a question or other screen display.

There are almost no clear examples of usage of suffixes. It's all been trial-and-error for me, and it is still this everytime I have to use or display a value.

BTW, "MEAN" was the translation of "MOYENNE" which was the Equation question "name", so it was not a reference to the native function, but a reference to the name of the question :)

Anyway, I actualy put .NAOK (in capitals) everywhere at first, unless otherwise noted... it's like the "TOKEN:" thing. I put it everywhere where values need to be displayed when in a token'ed survey...

Still, I understand totally your replies.

Thanx a lot

Eric
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose