Incorrect assignment from response to variable


Author
Message
allthedecs
allthedecs
Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)
Group: Forum Members
Posts: 5, Visits: 8
I'm having a problem where I'm assigning a slider response to a <values> item, but in the <summarydata> file the value saved is slightly off the actual response.

The command I'm using is:
values.unknown30bet = surveypage.unknown_urn_page.response/100

As an example, when looking in the raw data file I can see that the response was (accurately) saved as 647, but the value stored in the summary data file for values.unknown30bet is 6.4699999999999997513.

I've attached the code in case it helps, but I'm a bit of an amateur so I'm aware that it might be a bit messy!

Thanks in advance
Attachments
urntask.iqx (542 views, 23.00 KB)
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
allthedecs - Monday, August 13, 2018
I'm having a problem where I'm assigning a slider response to a <values> item, but in the <summarydata> file the value saved is slightly off the actual response.

The command I'm using is:
values.unknown30bet = surveypage.unknown_urn_page.response/100

As an example, when looking in the raw data file I can see that the response was (accurately) saved as 647, but the value stored in the summary data file for values.unknown30bet is 6.4699999999999997513.

I've attached the code in case it helps, but I'm a bit of an amateur so I'm aware that it might be a bit messy!

Thanks in advance

That's normal and a consequence of how computers represent integers (e.g. 647) vs real numbers (e.g. 6.47). For computers, everything comes down to binary, and it simply is the case that not every real number can be represented *precisely* as a binary value. (See https://en.wikipedia.org/wiki/Floating_point_numbers#Accuracy_problems for some canonical examples.) Basically, you incur a small loss of precision when you go from integers -> floating point representations, varying with the type of mathematical operation involved. All computer programs that do math deal with this, although you will often not notice because extra rounding or other tricks programs perform behind the scenes will hide those things from the user.

Edited 6 Years Ago by Dave
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
Dave - Monday, August 13, 2018
allthedecs - Monday, August 13, 2018
I'm having a problem where I'm assigning a slider response to a <values> item, but in the <summarydata> file the value saved is slightly off the actual response.

The command I'm using is:
values.unknown30bet = surveypage.unknown_urn_page.response/100

As an example, when looking in the raw data file I can see that the response was (accurately) saved as 647, but the value stored in the summary data file for values.unknown30bet is 6.4699999999999997513.

I've attached the code in case it helps, but I'm a bit of an amateur so I'm aware that it might be a bit messy!

Thanks in advance

That's normal and a consequence of how computers represent integers (e.g. 647) vs real numbers (e.g. 6.47). For computers, everything comes down to binary, and it simply is the case that not every real number can be represented *precisely* as a binary value. (See https://en.wikipedia.org/wiki/Floating_point_numbers#Accuracy_problems for some canonical examples.) Basically, you incur a small loss of precision when you go from integers -> floating point representations, varying with the type of mathematical operation involved. All computer programs that do math deal with this, although you will often not notice because extra rounding or other tricks programs perform behind the scenes will hide those things from the user.

To add, if this bothers you, you can do what many applications will do to mask the issue and apply formatting to the floating point result like so:

<surveypage unknown_urn_page>
/ stimulustimes = [0 = unknown_urn_pics, urncontents_label, unknownodds, quittext, maintask_header]
/ questions = [1 = slider.bet_slider]
/ showpagenumbers = false
/ showquestionnumbers = false
/ nextbuttonposition = (40%, 90%)
/ finishlabel = "Place bet"
/ navigationbuttonsize = (20%, 6%)
/ navigationbuttonfontstyle = ("Arial", 3.33%, false, false, false, false, 5, 1)
/ ontrialend = [
    if (list.unknownorderlist.nextvalue == 1) {values.unknown30bet = format("%.2f", surveypage.unknown_urn_page.response/100)}
    if (list.unknownorderlist.nextvalue == 2) {values.unknown40bet = format("%.2f", surveypage.unknown_urn_page.response/100)}
    if (list.unknownorderlist.nextvalue == 3) {values.unknown50bet = format("%.2f", surveypage.unknown_urn_page.response/100)}
    if (list.unknownorderlist.nextvalue == 4) {values.unknown60bet = format("%.2f", surveypage.unknown_urn_page.response/100)}
    if (list.unknownorderlist.nextvalue == 5) {values.unknown70bet = format("%.2f", surveypage.unknown_urn_page.response/100)}
]
</surveypage>

allthedecs
allthedecs
Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)Respected Member (457 reputation)
Group: Forum Members
Posts: 5, Visits: 8
Oh ok great, thanks for explaining!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search