Start a new topic

Leading zero for Numbers

Hello...


I want do use the current time to show on the display, but is the number < 10 there is only one sign.

How can I format the number with a leading zero (for example 11:05:07 instead of) 11:5:7)?


Joachim




You're question is ambiguous - format it in what?


If you are using version 38 of the Nextion Editor - in the Number component attributes: set length to 2

Or if from a number component to a text component in event code use: cov n0.val,t0.txt,2


If you are using Kylix and sending the time to a text component

  timestring := FormatDateTime('HH:MM:SS',now);

  serial.write(timestring);

If it is not a datetime value but rather In separate variables hour,minute,seconds then

  timestring := Format('%.2d:%.2d:%.2d',[hour,minute,seconds]);


if it is some other language, then a pseudo function for LeadingZeros


function LZeros (I : integer; b : byte) : String;

var tmp : String; x : integer;

begin

  tmp := InttoStr(I);

  for x := length(tmp) to b-1 do

    tmp := '0'+tmp;

  LZeros := tmp; 

end;


then use

  hourstring := LZeros(hour,2);


Hello Patrick,


I use Version 38 and I now found this feature - and it works!


Thank you


Joachim

Login or Signup to post a comment