Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Using decimal point in loops, Qt interferes

edited May 2013 in OpenSesame

Hello,

I'm experiencing an issue with Qt, which uses the dutch setting of comma for decimal point and ignoring the period in loops.
To clarify: in a delay discounting task I'm using the list in a loop to give me an amount each trial.
This works wonders when I use a comma, but my supervisor wants periods (as Sebastiaan stated before, the comma issue is something we should change...).

When I use periods in the loop, everything is fine as long as there is a decimal number, but for instance 27.00 becomes 27, visually not equal and thus a problem.

Is there any (easy) way to fix this?

Best,

Koen

Comments

  • edited 2:58AM

    Hi Koen,

    You could try using string values. If you're using my sample code, the text that is to be displayed is created within an inline_script, as a string. Within this same inline_script, you could add the following:

    dval = exp.get("val")
    
    sval = str(dval)
    
    if '.' not in sval:
        sval += '.00'
    
    ## rest of code, in which you use sval to create a text to display ##
    

    Good luck!

  • edited 2:58AM

    Hi Edwin,

    Thx for the quick response.
    I should have realized I can simply add them again, since only those values have no decimal.

    Topic closed!

    Best

    Koenraad

  • edited 2:58AM

    Just to clarify: This problem isn't due to Qt, but to the fact that OpenSesame automatically interprets variable types, as described in this discussion ...

    ... and on this page ...

    The value 1.0 (say) is interpreted as an integer, and the trailing zero is discarded. Another trick to get around this is by adding a small fraction to the number, like so:

    exp.set('my_var', self.get('my_var') + 0.00001)
    

    This will prevent my_var from being interpreted as an integer, and because OpenSesame by default only shows the first two decimals, you will get the result you want.

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.