Leading zeros

I’m trying to display an integer tag with leading zeros. I have a long number that is comprised of 4 3 digit long integers. So I want to join the 4 tags so they appear as one long number.

From what I’ve gathered by googling it I think I have to convert it to a string then format it to add the zeros. So I’d use a label not a numeric display but everything I have tried so far doesn’t work.

I did a search but couldn’t find anything either.
Thanks for the help

Where are you trying to do it? (Expression language? Scripting? On a tag? What kind of tag?)

Once you have the value, what are you going to do with it?

What version of Ignition do you have?

I would combine them into the full integer value in the PLC then read the single combined tag at the HMI.

Put a numeric label on the screen and select it.

In the Appearance area, find the “Number Format Pattern” entry.

Change it from #,##0.##
to 000,000,000,000.##

Technically, you don’t need the # values if you know it will never have a decimal. The Zeros tell it that no matter what you want those leading zeroes. That way you combine it in the PLC and format the display at the HMI to give you the total look you want.

If that’s not an option… well, you could do the same math at the HMI level. Make an expression tag. For the expression take the number that will be the left most entry and multiply it by 1,000,000,000, take the second left most group and multiply it by 1,000,000, multiply the 3rd group by 1,000, and finally take the current value of the right most group. Add this all together and bam, you’ve got the number you’re looking for. So if your tags were Num1, Num2, Num3, and Num4 the expression would look something like

(Num1 * 1,000,000,000) + (Num2 * 1,000,000) + (Num3 * 1,000) + Num4


Okay let me try to explain it differently

I have 4 integer tags coming from my PLC each tag is 0-999. They make up the portions of a whole number hundreds, thousands, millions, billions. This data is already displayed on on HMI and I want to also display it in Ignition. In the HMI I can easily just tell it the field length (three digits) and to fill with zeros. then use 4 fields to make it appear as one long number.

So what I need to do is join the 4 tags into one number. First I need it to fill in the number with zeros so 9 would like 009, 10 would look like 010. I could then either make them all look like one number in a single label or numeric display(“tag1”+“tag2”+“tag3”+“tag4”) or use 4 labels or numeric displays without boarders to look like one number like what was done on the HMI.

So my question is how do I make the value being displayed fill with zeros. I know I have to do it as a script. I have tried different configurations of script {tag}.zfill(3), ‘%03d’ % {tag}, and a few others I found on the internet. I know it can be done. But I’m missing something or doing it totally wrong.

You can do the formatting entirely within the expression language, then cast it to an integer to get an actual number out. I set up a quick test using three spinners, but you could substitute the tags:

toInt(numberFormat({Root Container.Spinner 1.intValue}, "000") + numberFormat({Root Container.Spinner 2.intValue}, "000") + numberFormat({Root Container.Spinner 3.intValue}, "000"))

The ‘000’ pattern signifies that the padding 0s are non-optional. If you’re going to have a result greater than ~2 billion then you’ll need to cast to a long, not an integer.

Make an expression tag -

(Tag1) + (Tag2 * 1000) + (Tag3 * 1000000) + (Tag4 * 1000000000)