[Solved] Countdown timer that always shows decimals

  • So i have a variable Time with a starting value of 30 and every 0.1 seconds it subtracts 0.1 and updates the text of a sprite font but there is a problem: every time the value hits an even number the text shows no decimals. I want the text to be like: 30.0 29.9 29.8 29.7 --> 29.1 29.0 Not like the way it is now: 30 29.9 29.8 29.7 --> 29.1 29

    I have tried all kinds of solutions that i can think of using zeropad(), find(), left(), right() and so on but nothing works.

    If someone have a confirmed working way to acheive this please share, it would be greatly appreciated!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So i have a variable Time with a starting value of 30 and every 0.1 seconds it subtracts 0.1 and updates the text of a sprite font but there is a problem: every time the value hits an even number the text shows no decimals. I want the text to be like: 30.0 29.9 29.8 29.7 --> 29.1 29.0 Not like the way it is now: 30 29.9 29.8 29.7 --> 29.1 29

    I have tried all kinds of solutions that i can think of using zeropad(), find(), left(), right() and so on but nothing works.

    If someone have a confirmed working way to acheive this please share, it would be greatly appreciated!

    have you tried something like "Float" system expression?

  • > So i have a variable Time with a starting value of 30 and every 0.1 seconds it subtracts 0.1 and updates the text of a sprite font but there is a problem: every time the value hits an even number the text shows no decimals. I want the text to be like: 30.0 29.9 29.8 29.7 --> 29.1 29.0 Not like the way it is now: 30 29.9 29.8 29.7 --> 29.1 29

    >

    > I have tried all kinds of solutions that i can think of using zeropad(), find(), left(), right() and so on but nothing works.

    >

    > If someone have a confirmed working way to acheive this please share, it would be greatly appreciated!

    >

    have you tried something like "Float" system expression?

    Yes but I could not get it to work. It seems that any float that ends with a .o is automaticly changed into an int.

  • Try this:

    Set value to (int(value*10/10)

    (this is to remove any possible digits after 1 decimal, as sometimes float numbers are displayed like 5.300000000009)

    Set text to str(value) & (int(value)=value ? ".0" : "")

    (this will add ".0" if the value is integer)

  • Yes but I could not get it to work. It seems that any float that ends with a .o is automaticly changed into an int.

    Me neither. But this works:

    Global number count = 300
    
    + System: Every 0.1 seconds
    -> System: Subtract 1 from count
    
    ----+ System: count%10 = 0
    -----> Text: Set text to int(count÷10)&".0"
    
    ----+ System: Else
    -----> Text: Set text to count÷10
    
    [/code:3cfa6wbg]
    
    I cant get it to work with floats so i have do divide in the textbox.
  • Try this:

    Set value to (int(value*10/10)

    (this is to remove any possible digits after 1 decimal, as sometimes float numbers are displayed like 5.300000000009)

    Set text to str(value) & (int(value)=value ? ".0" : "")

    (this will add ".0" if the value is integer)

    Thanks for the reply but when I try it decimals never shows at all

  • Sorry, missed one bracket, also change "int" to "round":

    Set value to (round(value*10)/10)

    Set text to str(value) & (int(value)=value ? ".0" : "")

  • Sorry, missed one bracket, also change "int" to "round":

    Set value to (round(value*10)/10)

    Set text to str(value) & (int(value)=value ? ".0" : "")

    Still doesn't work, now the timer value is always set 30.

  • >

    >

    > Yes but I could not get it to work. It seems that any float that ends with a .o is automaticly changed into an int.

    >

    Me neither. But this works:

    > Global number count = 300
    
    + System: Every 0.1 seconds
    -> System: Subtract 1 from count
    
    ----+ System: count%10 = 0
    -----> Text: Set text to int(count÷10)&".0"
    
    ----+ System: Else
    -----> Text: Set text to count÷10
    
    [/code:3hxlj5l5]
    
    I cant get it to work with floats so i have do divide in the textbox.
    

    Yep That works, just got to remember if I want a 50 sec timer I need to set it to 500. Thanx for helping!

  • It works for me:

    https://www.dropbox.com/s/xku35p1w3outu ... .capx?dl=0

    I could swear I did it the same way but obviously I didn't because this time your method works.

    My most humble apologies, and a big thanks for the help <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)