Welcome to the LimeSurvey Community Forum

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

different float as result of calculations

  • shiva522
  • shiva522's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #163454 by shiva522
Hello.

I analyzed the example given in the documentation for Limesurvey on the calculation of the weight index.
I tried to write about what they have as an example in the pictures. In general, everything works, but there is 1 but.

In the equation, this index is calculated using the formula:

ves / (rost / 100) * (rost / 100)

"rost" it's a Height
"ves" it's a Weight

As a result of the calculation, I have a semicolon as a delimiter.

When I (for the test) tried in this formula directly in the question to replace the variables "rost" and "ves" with specific digits (the same digits that I entered in the poll when it ran), my result is a number with a period as a separator.

All would be nothing, but when this number with a comma as a separator is analyzed further in the poll, what would be the conclusion based on the mass index about the person .. I'm getting nothing at the output!

The fact that this is the floating-point number I tested with the "is_float" function.


why is this happening?

With best regards
The topic has been locked.
  • shiva522
  • shiva522's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago - 6 years 2 months ago #163455 by shiva522
Replied by shiva522 on topic different float as result of calculations
I understood the difference.

if the language is Russian then a comma is used.

if English is a point.

Then the question is how to change that the point was everywhere as a separator of the whole and fractional part.

In this message, I sent a polling file. if you choose the language, English is considered normal. if you choose Russian - then the calculation is incorrect due to the use of a comma instead of a point as a separator of the whole and fractional part.

How to solve such a problem? The use of English as the main language is undesirable because our language is the main Russian language.
Last edit: 6 years 2 months ago by shiva522.
The topic has been locked.
  • c_schmitz
  • c_schmitz's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
6 years 2 months ago - 6 years 2 months ago #163461 by c_schmitz
Replied by c_schmitz on topic different float as result of calculations
I can't see the problem here. Internally LimeSurvey always uses the dot as decimal separator.
An equation always gives back a string unless you set the additional attribute for the equation quesiton to be a float ( manual.limesurvey.org/QS:Numbers_only )

Best regards

Carsten Schmitz
LimeSurvey project leader
Last edit: 6 years 2 months ago by c_schmitz.
The topic has been locked.
  • shiva522
  • shiva522's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago - 6 years 2 months ago #163503 by shiva522
Replied by shiva522 on topic different float as result of calculations
I set "Numbers only" for equations. After this, the equation is considered correct when specifying integer values ​​of weight and height. However, if I enter in the fields the "height" or "weight" of the fractional values ​​then as is "is_float" shows I get no float value and the equation does not work correctly. For russian language the result of division is string. for english result of division is float and this equation considered correct..

fields "height" and "weight" have type "input numbers"

It's unclear if in limesurvey always uses '.' for the separation of the whole and fractional parts, why do such problems occur on the same formula when assigning Russian and English? I did not find anything
in settings of fields "input numbers" on this issue.


Maybe it's worth adding the settings for the float type to the input field number, if such a problem .. or is it an error that has not yet been noticed?
Last edit: 6 years 2 months ago by shiva522.
The topic has been locked.
  • c_schmitz
  • c_schmitz's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
6 years 2 months ago #163506 by c_schmitz
Replied by c_schmitz on topic different float as result of calculations
Use str_replace to replace the comma ',' from the user input with a dot '.' then your str_float will work properly.

Best regards

Carsten Schmitz
LimeSurvey project leader
The topic has been locked.
  • shiva522
  • shiva522's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago - 6 years 2 months ago #163512 by shiva522
Replied by shiva522 on topic different float as result of calculations
I used the function str_replace. If the height or weight is float the result is string If the height and weight are integers then without str_replace I get float.

I get information about the type using the functions is_float, is_numeric, is_string. so this method does not work

As I understand it str_replace works with a string and returns a string. And if you need to process a number, then this line needs to be converted to float.

But there is no such function in limesurvey.

looked in functions php on the basis of which I understand how those functions are implemented that are in limesurvey.

php.net/manual/ru/function.floatval.php

There is a floatval but in limesurvey it is not.
Last edit: 6 years 2 months ago by shiva522.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose