Display 0 for NaN

I have an expression tag that takes a tag value and divides it by another tag value. When these tags reset in the evening the expression tag changes to NaN im assuming because its dividing by 0 when one of the other tags resets to 0. Is there a way to make NaN display 0 instead of NaN? At the end of the day its not a huge deal because the tag serves its purpose its intended for, however, visually it is bothering me for the time period the division tags are at 0 until they start counting again.

Hopefully that makes sense....

If it's an expression tag, you could use something like

if ({divider_tag} != 0,
    {some_value} / {divider_tag},
    0
)
4 Likes

Is NaN treated as an error? If so, you could use the try function,
https://docs.inductiveautomation.com/display/DOC80/try

Unfortunately try() won't work, as the actual division doen't generate an error. The TypeConversoin error happens after. Use Pascal's. :slight_smile:

3 Likes

I thought I had this sorted out but I was wrong. Let me try to clarify a bit more.
You have 1 expression tag here and 2 OPC Tag....all floats.

Main Tag A = Expression Tag value that is displayed on ignition screen. We call this main tag because its the one giving the type conversion error.
Tag B = OPC tag Value that is reset daily at 5am to 0.
Tag C= OPC Tag Value that is reset daily at 5am to 0.

Main Tag A is simply using the expression {Tag B} / {Tag C}. The value that is displayed gives us the type conversion error because at 5am Tag B and Tag C are being reset to 0, therefore Tag A is trying to do 0 divided by 0, in which lies the issue. Once Tag B and C have values, Tag A works perfectly as intended, i just dont want NaN being displayed on the screen after the reset happens.

I know im close but still doing something wrong. I did get the error to go away but the tag then didnt have any value at all. Appreciate the help.

Show your expression in your expression tag. We can't identify the mistake you are making without seeing it.

1 Like

if ({Tag_A} != 0,
{Tag_B} / {Tag_C},
0
)

Removes the Type_ErrorConversion from the value but then doesnt actually do the expression calculation. I may be understanding the syntax incorrectly. My understanding is if Tag A doesnt equal 0 then it will do the expression cal Tag B / Tag C. If it does equal 0, set the value to display 0.....

If you want to avoid division by 0, you need to check the value that will be used to divide.

Replace tag_A by tag_C in the expression's condition.
Which is exactly what I suggested previously.

I also tried that with the same result. Error in value is gone but it then doesnt actually do the division of the tags....

Where did you use that expression ?
This will result in a value, as long as tag_c is not 0.

As stated above, Tag C gets reset to 0 at 5am every day. I used the expression in the expression field of the tag.

Don't use Tag_A in the expression. That makes a loop, and is wrong anyways. I recommend this:

{Tag_B} / if({Tag_C}, {Tag_C}, 1.0e60)

The trailing large constant is to gracefully handle any execution that happens between Tag_C and Tag_B getting set to zero.

1 Like

Then at 5am every day, tag_c won't be used in the calculation, because of the condition, and you'll just get 0.

Thank you sir! Appreciate you giving me a solution. Works perfectly!

You arent understanding fully i dont think. pturmel helped me out with a solution. Thank you for trying.

This worked properly yesterday after the morning reset but today for some reason the value is staying at 0 and not doing the division. Any ideas?

We don't know what your code is. Post your expression code and format it using the </> button.

1 Like

Is the expression tag assigned to a tag group?

If you read the entire thread you know what my code is. pturmel posted it above....

Its just assigned to the Default tag group.