double digits

Hi all, i’m creating a simple minutes/seconds countdown, but i’d like to have the numbers in double digits (i.e, 05:09) instead of single digits (5:9).

How can in convert a single digit number to a double digit one?

thank you in advance.

There’s Python zfill() that works quite well for that type of thing:

tutorialspoint.com/python/string_zfill.htm

Indeed, it’s perfect.

So, i have to use a evaluate dat? a script dat? the sintax should be str(op(‘sec’)[0,0]).zfill(2) or something similar (where sec is the name of the DAT with the seconds value)?

It works fine in the textport,for example

2.zfill(2) gives “02”

in an executeDAT the error is: line 18, in tableChange
AttributeError: ‘td.Cell’ object has no attribute ‘zfill’

I’m a total beginner in scripting what’s wrong?

op('sec')[0,0].val.zfill(2)

You should use .val to always get the value from a cell. Otherwise, you are grabbing the cell object itself with op()[0,0] and hoping that it will automagically cast the value for you, but if you put .val you’ll always get the actual value.

Also all data in DATs are strings, so you dont need to string it again. Even an int put into a DAT table becomes a string once it reaches the table.

Elbruz thank you very much, it works perfectly now! :slight_smile:

Attaching the countdown project for anyone interested.
CD_forum.toe (4.99 KB)