Text stim presenting digits with unwanted decimals

OS: Win 10
PsychoPy version: 3.1.2 (but also occurs in most recent)
Standard Standalone? y
What are you trying to achieve?:
I have a running digit span task, where in a trial, each text stimulus component (Dig1 to Dig11) represents a single digit. The text is defined within each component as $Dn (e.g. in the Dig10 text component, the text is $D10).

The numbers feed from the excel file as expected, but for some reason, psychopy presents some of these digits to one decimal place (i.e. 4.0), while others are presented as whole numbers (i.e. 4). Needless to say, in the excel file they are just whole numbers, and it is whole numbers that I would like to present. It seems as though the first 3 digits (components Dig1 to Dig3) are presented as whole numbers, and subsequent ones (components Dig4 to Dig11) are presented to one decimal place.

What did you try to make it work?:

  • I checked that all of the text components within psychopy have an identical set-up (aside from start time).
  • I tried changing the formats of the values in the excel file to ensure they match; I tried general, text and number.
  • I tried making a new excel file from scratch to ensure that all numbers were typed in in exactly the same manner.
  • I tried adding a space after the numbers in the excel file.
  • I tried looking in the coder view to see whether I could identify any differences (I couldn’t).

None of these efforts have resulted in any changes to the presentation, and I am at a loss as to what may fix this or why it is happening in the first place.

Hi @jretz, is this for an online JavaScript tasl, or a local Python task?

@dvbridges sorry - I should have made that clear. It is at present a local Python task, though if it would be helpful to see the task, it is saved to my Pavlovia repository here: https://gitlab.pavlovia.org/jenny.retzler/runningdigitspan

Let me know if you need further info.

Thats ok, I just needed to know whether I can use a Python specific solution. In your text component, you can use the following to round the numbers:

$round(float(Dn))

This will ensure that any number passed to Dn will be converted to a float (just in case it is imported as a string) and then will be rounded to 0 decimal places.

1 Like

Wonderful - thanks @dvbridges. In case anyone has this issue in the future, using that code initially gave me another problem:

Dig6.setText(round(float(D6)))
TypeError: float() argument must be a string or a number, not ‘NoneType’

This seemed to be caused by the fact that different trials have different lengths of digits, so sometimes I was not defining these components. I added zeros to empty cells in my conditions file (they aren’t presented anyway so it doesn’t make any difference to the task presentation or data files) and this issue resolved so now it all seems to be working fine.

1 Like