It seems that using the "round()" command sometimes leads to wrong results.
Simple example (see also attachement): If you program a question with "{100-round(14.28*7,2)}" as text to be displayed, LimeSurvey displays "0.040000000000006" although the correct number would be "0.04".
I stumbled upon this because I programmed a survey where people enter a number that is later used in different calculations (of which the the results are displayed to the participant). So this problem remains if you work with a number that was entered by a partipant and it also remains if you store each step of the calculation in a separate question/equation. The weird thing is that it seems to happen only for very specific combinations. If you do the calcuation in the simple example above with 14.27 instead of 14.28 for example, the correct result is shown. If you use 14.281 instead of 14.28 the result shown is still incorrect.
Am I missing something here? Any help is greatly appreciated. I used LimeSurvey Version 5.2.2 to program the example but the problem also exists for Version 3.22.1+200129.
Thanks a lot for your fast reply! Okay, I see it has nothing to do with the rounding but that it applies more generally.
I must admit I am not familiar with floating-point arithmetic and the IEEE 754 specification. I did some research and it seems some rounding error is inevitable. Is there any way to deal with this more generally in LimeSurvey? If some calculation is involved, it seems there might always be cases where the calculation is not "exact" and leads to wrong restults. How to avoid this? (If the number to be displayed should include no more than a certain number of decimal places one could of course always just apply the rounding command to the final result, but what if exact results should be displayed without any rounding involved?)
Add the round at end of formula,
Wrap formula with round.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
Thank you for the suggestion. That's of course possible when it is clear how many decimal places one wants to have at most (see also my last sentence in previous post). But it does not help if I want to report exact results (that differ in the length of their decimal places).