Welcome to the LimeSurvey Community Forum

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

Sum dont work

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #208739 by Joffm
Replied by Joffm on topic Sum dont work
Seems to be a php bug.

Small php-program:
Code:
<?php
echo "Sum of 90, 0.4, 0.4, 1.2 and 8<br><br>";
$i1=90;
$i2=0.4;
$i3=0.4;
$i4=1.2;
$i5=8;
$sum=$i1+$i2+$i3+$i4+$i5;
echo "Sum: ".$sum."<br>";
echo "Sum equal 100: ";if($sum==100) {echo "true";} else {echo "false";}
?>


Result:


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 4 months ago by Joffm.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #208742 by DenisChenu
Replied by DenisChenu on topic Sum dont work
Arg : totally right …

We use array_sum in Expression Manager / Script :
Code:
<?php
echo "array_sum([90,8,0.4,0.4,1.2]) = ".array_sum([90,8,0.4,0.4,1.2])."<hr>";
 
echo "array_sum([90,8,0.4,0.4,1.2]) == 100 : ";
echo (array_sum([90,8,0.4,0.4,1.2]) == 100) ? 'true' : 'false';


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.
Last edit: 3 years 4 months ago by DenisChenu.
The topic has been locked.
  • ollehar
  • ollehar's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
3 years 4 months ago #208744 by ollehar
Replied by ollehar on topic Sum dont work
This is unrelated to PHP. It's how floating-point precision works. Can you use integers instead?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #208752 by DenisChenu
Replied by DenisChenu on topic Sum dont work
@ollehar : here, it's using included attribute : Maximum sum value

@Joffm alredy give a solution for pown expressoion.

I think we need a global solution : github.com/LimeSurvey/LimeSurvey/blob/44...core_helper.php#L266

Maybe array_sum(array_map([the array])) ?

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.
  • ollehar
  • ollehar's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
3 years 4 months ago #208754 by ollehar
Replied by ollehar on topic Sum dont work
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #208758 by DenisChenu
Replied by DenisChenu on topic Sum dont work
OK,
you create the pull 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.

Lime-years ahead

Online-surveys for every purse and purpose