Forum Discussion

WilliamRyan-dba's avatar
WilliamRyan-dba
Community Member
6 months ago

decimal places in numeric variable

Hi there,

I have an interaction with a number of numeric entry fields, and the default for the fields seem to be whole numbers. I have buttons that increment the values of the fields by +/- 0.25. I would prefer the whole numbers to be displayed with 2 decimal places also. I don't see how to do it. Any help is appreciated... 

  • AndrewHanley's avatar
    AndrewHanley
    Community Member

    Hi William.

    When ive had to do this sort of thing in the past, the Storyline number variable automatically defaults to two decimal places, so I use that instead of a numeric data entry text field.

    Then simply use your buttons and a "Adjust Variable" trigger, to set the variable value correctly.

    • WilliamRyan-dba's avatar
      WilliamRyan-dba
      Community Member

      I don't know what I'm missing. I add a numeric variable, and if I set the default value to "0.00", the variable stubbornly reverts to "0". The other interactions work as expected: the increase and decrease value by 0.25 correctly sets the decimal place, but when the number gets to a whole number, there are no decimal places. 

      • SteveGannon's avatar
        SteveGannon
        Community Member

        Hi William,

        Storyline does not display trailing zeros. You can work around this with a bit of JavaScript (see attached). This involves sending the numeric value to JavaScript, having JavaScript round the value to two decimal places, convert it to a text value with the trailing zero (or zeroes), and then having JavaScript assign that to a text variable in Storyline. (Note: the custom text variable must already be created in Storyline before executing the JavaScript.)

  • That's strange,  because I did set it up as a number variable.  I'll have a look and try again...