Read Tag with Formatting - Best Practice

Is it possible to use a binding to read a tag value with it’s format already applied?

Currently I read the raw value and the format string using two separate bindings. Then I format the value using an expression binding and numberFormat(). It feels as though this can be achieved in a simpler manner - any suggestions are appreciated.

Example of current method:

Assuming that _value and _format are also just Expression Bindings, then you can just place those Expressions together inside of the single numberFormat Expression.

What you are doing with _value and _format are what you need to do if you intend to use indirect tag binding with this label. Consider placing the expression on _valueFormatted directly on props.text for the label.

_value and _format are both tag bindings, accessing the tags Value and FormatString, respectively. So unless I want to use the tag()function within the expression, which I avoid due to potential issues, I don’t see a method to combine this into one expression binding.

Thank you for the reply! It sounds like I am out of luck.

I was hoping I was missing something obvious, since the value is already formatted properly in the tag browser.

Yeah, I never use tag() as I’ve heard it should be avoided, though I’m not sure why, exactly.

Heh: So many rants:

https://forum.inductiveautomation.com/search?q=%40pturmel%20%22tag()%22%20order%3Alatest

2 Likes

Quoting a response in that list that explains it:

1 Like

Here's a method to use the FormatString defined in the tag. It might work for you. The sample memory tag is a float with value = 32.1234567,

  • Create three custom properties on the label.
  1. Right-click on the tag, copy path, and paste it in here.
  2. Create an indirect tag binding on custom.tagValue.
  3. Create an indirect tag binding on custom.formatString.
  4. Create an expression binding on props.text.

    Expression: numberFormat({this.custom.tagValue}, {this.custom.formatString})

You should now be able to copy the label as often as required, set the tagPath and everything should work.

Adding the EngUnit is an exercise left to the reader.

Here's a link to a post written by a younger me: Creating a Perspective tag-drop view (almost) [solution]. It might give some ideas.

1 Like