- Posts: 4
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Formatting numbers in calculations
- skwtayler
- Topic Author
- Offline
- New Member
Less
More
9 years 10 months ago #109333
by skwtayler
Formatting numbers in calculations was created by skwtayler
Hi there,
I have a survey that utilises a number of calculations to output an answer.
Many of these are basic sums.
My question is whether it is possible to format the numbers for ease of use.
For example I'd like 1000000 to be displayed as 1,000,000 or even 1 000 000
At the moment if I format then it affects the output of the calculation.
Perhaps someone could point me to the correct way to format the fields?
Thanks
I have a survey that utilises a number of calculations to output an answer.
Many of these are basic sums.
My question is whether it is possible to format the numbers for ease of use.
For example I'd like 1000000 to be displayed as 1,000,000 or even 1 000 000
At the moment if I format then it affects the output of the calculation.
Perhaps someone could point me to the correct way to format the fields?
Thanks
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1128
- Thank you received: 329
9 years 10 months ago #109346
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Formatting numbers in calculations
Never used (I didn't manage billion of $) but i suppose you are looking forthis kind of expression:
Have a look to the " bible " of all expression manager functions
Ben
Code:
{number_format(123456789)}
Have a look to the " bible " of all expression manager functions
Ben
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- skwtayler
- Topic Author
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
9 years 10 months ago #109503
by skwtayler
Replied by skwtayler on topic Formatting numbers in calculations
Hi Ben.
Thanks so much for the response we have tried everything but when applying this to the input fields it doesn't work on the "total" field. As in, the result seems to be affected by the inputs.
Is there someway to mask the input field but have the entries sent through only as integers?
Here is the link if you want to see what I'm talking about.
eluminousdev.com/cova_advisory/764664/lang-en
Thanks so much for the response we have tried everything but when applying this to the input fields it doesn't work on the "total" field. As in, the result seems to be affected by the inputs.
Is there someway to mask the input field but have the entries sent through only as integers?
Here is the link if you want to see what I'm talking about.
eluminousdev.com/cova_advisory/764664/lang-en
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1128
- Thank you received: 329
9 years 10 months ago #109508
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Formatting numbers in calculations
maybe using the EM
"round" or "intval"
functions
(you may have a look at "ceil" & "floor" as well)
for example using "round" to get a number with 2 decimals:
{round(sum(arg1, arg2),2)}
if arg1=2.1111 & arg2=2.222 the result will be 3.33
I suppose (not tested) the following syntax will return an integer
{round(sum(arg1, arg2),0)}
if arg1=2.1111 & arg2=2.222 the result will be 3
I hope that someone else can give you more accurate help; Maybe using javascript instead EM.
(you may have a look at "ceil" & "floor" as well)
for example using "round" to get a number with 2 decimals:
{round(sum(arg1, arg2),2)}
if arg1=2.1111 & arg2=2.222 the result will be 3.33
I suppose (not tested) the following syntax will return an integer
{round(sum(arg1, arg2),0)}
if arg1=2.1111 & arg2=2.222 the result will be 3
I hope that someone else can give you more accurate help; Maybe using javascript instead EM.
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1128
- Thank you received: 329
9 years 10 months ago #109512
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Formatting numbers in calculations
I attached a sample survey if it could be helpful to someone...
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Attachments:
The topic has been locked.
- skwtayler
- Topic Author
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
9 years 10 months ago #109695
by skwtayler
Replied by skwtayler on topic Formatting numbers in calculations
Hi Ben, unfortunately that didn't work. The problem is we can apply the formatting but it breaks the calculations. We need some sort of 'mask' that will show the formatting on the frontend but parse the actual integer in to the db.
Anyone have any ideas? There must be a way of doing this...
Anyone have any ideas? There must be a way of doing this...
The topic has been locked.
- skwtayler
- Topic Author
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
9 years 10 months ago #109698
by skwtayler
Replied by skwtayler on topic Formatting numbers in calculations
Hi Ben, would you be able to chat on Skype? Perhaps we can find a solution for this together.
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1128
- Thank you received: 329
9 years 10 months ago #109700
by Ben_V
I understand your issue now... The bad news is that I've no idea on how to make it work ...
Probably only with javascript.
I hope that someone else could give you a hand too
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Formatting numbers in calculations
The problem is we can apply the formatting but it breaks the calculations. We need some sort of 'mask' that will show the formatting on the frontend but parse the actual integer in to the db.
I understand your issue now... The bad news is that I've no idea on how to make it work ...
Probably only with javascript.
I hope that someone else could give you a hand too
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
9 years 10 months ago #109776
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Formatting numbers in calculations
Hi,
I think you must use 2 system:
- Do all calculation in Hidden Equation question type.
- Show the result with 'text display' question tye (or put it in group description).
Example:
CALCUL1 : {sum(Q1,Q2,Q5)}
DISPLAY1 : {number_format(CALCUL1)}
I think you must use 2 system:
- Do all calculation in Hidden Equation question type.
- Show the result with 'text display' question tye (or put it in group description).
Example:
CALCUL1 : {sum(Q1,Q2,Q5)}
DISPLAY1 : {number_format(CALCUL1)}
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: jboogie21
The topic has been locked.
- jboogie21
- Offline
- Senior Member
Less
More
- Posts: 45
- Thank you received: 7
9 years 3 months ago #115922
by jboogie21
Replied by jboogie21 on topic Formatting numbers in calculations
Denis your post helped.
Now my next question, does the "number_format" function with EM allow to control decimal placement? It doesn't seem to, but I'm not a programmer and can't tell if it should or not.
Now my next question, does the "number_format" function with EM allow to control decimal placement? It doesn't seem to, but I'm not a programmer and can't tell if it should or not.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
9 years 3 months ago #115928
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Formatting numbers in calculations
Hi,
Not actually, must be a feature request ....
Not actually, must be a feature request ....
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.