This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Force 2 digit
#1
Hi,

Is it possible that in an input field two digits are always displayed?

For example when 0 is entered in the input field 00 would be shown.

Thanks.
Reply
#2
Which graphical element do you have in mind?
------------------------------
Ctrl+F5
Reply
#3
(03.11.2023, 08:33)Daniel Wrote: Which graphical element do you have in mind?

Hi,

An object input box (for example for 1 byte object), something like this:

Reply
#4
As this is not a real number, don't think that this is possible.
------------------------------
Ctrl+F5
Reply
#5
(06.11.2023, 11:29)Daniel Wrote: As this is not a real number, don't think that this is possible.

Ok thanks
Reply
#6
maybe with script from byte to string... test... and add some 0 in some case ?
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#7
Hi,

you can try as Domotiqa recommended. Possible variant - show your data with zeroes, when you need enter data - zero is not so important may be.

Long time ago I did something you need with hour and minutes less 10, I wanted zero in front:

Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
time = { day = wday, hour = now.hour, minute = now.min, second = now.sec, } h1 = now.hour m1 = now.min ms = now.month weekday1 = wday if now.hour == 0 then h1 = "00" end if now.hour == 1 then h1 = "01" end if now.hour == 2 then h1 = "02" end if now.hour == 3 then h1 = "03" end if now.hour == 4 then h1 = "04" end if now.hour == 5 then h1 = "05" end if now.hour == 6 then h1 = "06" end if now.hour == 7 then h1 = "07" end if now.hour == 8 then h1 = "08" end if now.hour == 9 then h1 = "09" end if now.min == 0 then m1 = "00" end if now.min == 1 then m1 = "01" end if now.min == 2 then m1 = "02" end if now.min == 3 then m1 = "03" end if now.min == 4 then m1 = "04" end if now.min == 5 then m1 = "05" end if now.min == 6 then m1 = "06" end if now.min == 7 then m1 = "07" end if now.min == 8 then m1 = "08" end if now.min == 9 then m1 = "09" end if now.hour == 0 then h1 = "00" end if weekday1 == 1 then weekdayru = "Понедельник" end if weekday1 == 2 then weekdayru = "Вторник" end if weekday1 == 3 then weekdayru = "Среда" end if weekday1 == 4 then weekdayru = "Четверг" end if weekday1 == 5 then weekdayru = "Пятница" end if weekday1 == 6 then weekdayru = "Суббота" end if weekday1 == 7 then weekdayru = "Воскресенье" end

Simple but works. In result I see time with zeroes in front and weekdays text in required language. This is just like an idea. And of course you need take in mind data types and convert it if needed..

BR,

Alex
Reply
#8
You can simply use string.format:
Code:
1234
val = 1 str = string.format('%02d', val) -- pad with 0 up to 2 chars in width log(str) -- will log "01"

For converting number to a string you can either use Custom values or a table instead of multiple IFs:
Code:
12345678
values = {   [1] = 'Value 1',   [2] = 'Value 2',   [3] = 'Value 3', } val = values[ 2 ] log(val) -- will log "Value 2"
Reply


Forum Jump: