Forum Home › Forums › Understanding the Software › Using Formulas › Leading zeros
- This topic has 14 replies, 4 voices, and was last updated 2 years, 3 months ago by SGG.
-
AuthorPosts
-
November 16, 2016 at 2:15 pm #1732RobParticipant
How can I display a leading zero on a number?
Using the time example, I use a separate dynamic text element for the hours and minutes, but for less than 10 minutes the display looks like:
12: 1
and should look like:
12:01
I have tried adding a new Number format to the table of “DD” with zero decimal digits, but this didn’t work.
November 16, 2016 at 5:40 pm #1733MikhailModeratorI see…
I can suggest a hack: put a static text with 0 below the dynamic text. You should use a font with the same width of symbols, auto size and right align for dynamic text.
Most likely, the formatting will be implemented in the next major update.January 22, 2022 at 11:31 am #9974SGGParticipantHello Mikhail,
concerning the above statement by Rob “Using the time example, I use a separate dynamic text element for the hours and minutes…”is there a better way to combine hours and minutes, and have this displayed as a single entity in table view?
January 22, 2022 at 4:29 pm #9976manjey73ParticipantThey can be displayed as ASCII text by applying time formatting. It seems that there are corresponding formulas in C#.
Show your example how you display time on a mnemonic circuit
- This reply was modified 2 years, 3 months ago by manjey73.
January 22, 2022 at 7:43 pm #9978SGGParticipantThe link below is a picture showing how the hours and minutes occupy two rows instead of one.
https://drive.google.com/file/d/1lmG6N2BrYfohXd6pM-cuSkLfmNBUVOzX/view?usp=sharing
Under T4 Availability,
the next row = 0 hours
the next row = 1 minutescan I have it as 0:1 on a single row in table view?
January 22, 2022 at 8:44 pm #9979manjey73ParticipantI think you can, you need another calculated channel and use the formula to put it in time. If you are satisfied that it will show the time, but here you need to try with formulas depending on how you want to see the view. The simplest thing is to enter the data in DateTime and tell the channel to display only the time
January 22, 2022 at 8:55 pm #9980manjey73Participantdouble dt = new DateTime(Year, Month, Day, Hours, Minute, Seconds).ToOADate()
You need something like this, not sure if the formula is correct, not tested. Where, instead of hours and minutes, you should put your data, as far as I remember, by converting it to int
Year, day, etc. can be specified 0
- This reply was modified 2 years, 3 months ago by manjey73.
January 23, 2022 at 6:05 am #9984SGGParticipantHello Manjey,
I’ve tried it, not working. I’m not so good with formulas but this is what i did based on your earlier post.I INPUTED THIS IN FORMULA TABLE:
double Dt(Year, Month, Day, Hours, Minute, Seconds)
{ return DateTime().ToOADate();
}AND I INPUTED THIS IN CHANNEL FORMULA;
Dt(0,0,0,Val(6311), Val(6312), 0)Please guide me further.
January 23, 2022 at 6:25 am #9985manjey73Participantdouble Dt(double hours, doble minute)
{
return new DateTime(0, 0, 0, Convert.ToInt32(hours), Convert.ToInt32(minute), 0).ToOADate();
}In channel formula Dt(Val(6311), Val(6312))
Format channel – Time
If you transmit only hours and minutes, then in theory this is how it should be
January 23, 2022 at 6:44 am #9986manjey73ParticipantIt is impossible to make a year, month, day with zeros in this version, I just made a formula in the channel
new DateTime(2022, 1, 1, 2, 3, 0).ToOADate()
Where 2 and 3 are your channels of hours and minutes. Right in the channel they can be written like this
new DateTime(2022, 1, 1, Convert.ToInt32(Val(6311)), Convert.ToInt32(Val(6312)), 0).ToOADate()
January 23, 2022 at 6:50 am #9987manjey73Participantdouble myDT(double hours, doble minute)
{
DateTime ddt = DateTime.Now;
return new DateTime(ddt.Year, ddt.Month, ddt.Day, Convert.ToInt32(hours), Convert.ToInt32(minute), 0).ToOADate();
}in channel
myDT(Val(6311), Val(6312))
format channel – Time
But it will show seconds, If you want without seconds, then it will be a text field converted from time, with an indication of the display format and subsequent translation from ASCII to an array of bytes, and the format of the ASCII Text cell
- This reply was modified 2 years, 3 months ago by manjey73.
January 23, 2022 at 6:58 am #9989SGGParticipantHello Manjey,
It worked perfectly…Thanks a lot, you just made my day.January 23, 2022 at 7:02 am #9990manjey73ParticipantYou can make a general formula, for example, for applying a record in the maintenance time channel.
double myDT(double year, double month, double day, double hours, doble minute) // Without seconds
{
int y = Convert.ToInt32(year);
int mh = Convert.ToInt32(month);
int d = Convert.ToInt32(day);
int h = Convert.ToInt32(hours);
int m = Convert.ToInt32(minute);
return new DateTime(y, mh, d, h, m, 0).ToOADate();
}Then it can be used for different purposes. But you will have to specify the year, month and day every time. For your case, it is simple to specify and set the Time channel format
myDT(2022, 1, 1, Val(6311), Val(6312))
January 23, 2022 at 7:05 am #9991manjey73ParticipantFor example, you can record the maintenance time of some equipment in the calculation channel and then compare it with the current one somewhere and create messages.
myDT(2023, 5, 15, 10, 0)
Year 2023, month 5, 15th, 10 am
January 23, 2022 at 11:12 am #9993SGGParticipantI tried this, it works however the second is still showing. Thanks for your urgent response.
-
AuthorPosts
- You must be logged in to reply to this topic.