Logic Machine Forum
Force 2 digit - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Force 2 digit (/showthread.php?tid=5072)



Force 2 digit - jmir - 03.11.2023

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.


RE: Force 2 digit - Daniel - 03.11.2023

Which graphical element do you have in mind?


RE: Force 2 digit - jmir - 06.11.2023

(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:




RE: Force 2 digit - Daniel - 06.11.2023

As this is not a real number, don't think that this is possible.


RE: Force 2 digit - jmir - 07.11.2023

(06.11.2023, 11:29)Daniel Wrote: As this is not a real number, don't think that this is possible.

Ok thanks


RE: Force 2 digit - domotiqa - 11.01.2024

maybe with script from byte to string... test... and add some 0 in some case ?


RE: Force 2 digit - AlexLV - 11.01.2024

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:
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


RE: Force 2 digit - admin - 12.01.2024

You can simply use string.format:
Code:
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:
values = {
  [1] = 'Value 1',
  [2] = 'Value 2',
  [3] = 'Value 3',
}

val = values[ 2 ]
log(val) -- will log "Value 2"