Add tag value and text to a text box + cut/round(real) value

Hi.
I have this real value that has 15 decimals (unfortanely).
I wish to update a textbox with this real value, but round it down to 2-3 decimals and att “mbar” in the end.

I have tried the propertyChange with:

event.source.text = system.tag.readBlocking(["[default]zB1ADFilter/MovAvg.value)"]) + " mbar"

But this does not seem to work, adding round to the tag causes an error that round is not defined etc.

Perhaps there is a better way to do this other than propertyChange on the textbox?

Use an expression and use numberFormat({value}, '0.000') + ' mBar'

I tried this:
event.source.text = numberFormat(system.tag.readBlocking(["[default]zB1ADFilter/MovAvg.value)"]), ‘0.000’) + " mbar"

But the error i get is numberFormat is undefined:

Traceback (most recent call last):
  File "<event:propertyChange>", line 1, in <module>
NameError: name 'numberFormat' is not defined


Ignition v8.1.10 (b2021090812)
Java: Azul Systems, Inc. 11.0.11

Expression Functions and *
System Functions

are different part, try this.

And , the return object of system.tag.readBlocking is a list, try:

event.source.text = str(round(system.tag.readBlocking(["[default]zB1ADFilter/MovAvg.value)"])[0].value,2)) + " mbar"

@SKA, just as an aside, when you start a thread, it’s good to know what version of Ignition you’re using, and whether it’s vision or perspective, as the answers so far have already gone into the weeds with both. :wink:

Bind the text property to an expression, using the one @nminchin supplied.

I use V8.1.10 + Vision module, not perspective.

My text field does not have expression what i can see, only scripting and does not look anything like the image @nideyijuyidong posted.

Sorry, I never used Vision… :rofl:

This is why it’s useful to state. :slight_smile:

Click on the ‘chain link’ at the Text property.

Choose expression on left side of the dialog box. Expression in your case:

numberFormat({[default]zB1ADFilter/MovAvg}, '0.000') + ' mBar'

2 Likes

Thanks.
After some debugging here and there (compared to example above)
I now got it to show as i wished

press

1 Like