# UDT Parameter math is not evaluating correctly

**URL:** <https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [June 17, 2021, 5:41pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911 "2021-06-17T17:41:42Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyrel.parker](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tyrel.parker](https://forum.inductiveautomation.com/u/tyrel.parker)\
**Post date:** [June 17, 2021, 5:41pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/1 "2021-06-17T17:41:42Z")

</div>

This does not work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f54a82716dd007d673f65d9f4c9e1da15917ec84.png)

Note that the Description worked.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2bc4620d3843bab74d3f0e1d50bee394623a946c.png)

Actual OPC path for the alarm: ns=1;s=[PL\_STACKER]PL\_Stacker.Alarm[0].2

Parameters.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/e/9e95890fd940f0fc31a3fb300b9290bcfe222537.png)

The alarm configuration with the parameter math.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/9689c6a11c68fa2ecfa1ef50f754202d3fc5f719.png)

Testing…  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed087ab904d5682302ab9cc68b8987339dd74bdf.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd8d2258434d866ae83dae6da39fcd35b7cfc132.png)  
Both failed…

The non math reference obviously works fine.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4de801f440bfd5b8a3671708a6a226f20ee9a204.png)

Am I doing this wrong? The documentation seems pretty clear. Any suggestions?

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 7:27pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/2 "2021-06-17T19:27:31Z")

</div>

Hi @tyrel.parker, I might be missing something but wouldn't your expression return a path of:

```auto
ns=1;s=[PL_STACKER]PL_Stacker.Alarm[0.125].2

```

I think the error may be resulting from the array index not being an integer.

> [@tyrel.parker](#):
>
> Testing…  
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed087ab904d5682302ab9cc68b8987339dd74bdf.png)  
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd8d2258434d866ae83dae6da39fcd35b7cfc132.png)  
> Both failed…

If you're referring to the `Bad_ReferenceNotFound`, I think this is because the expressions are not valid tag paths.

---

<div class="post-metadata">

**Author:** ![tyrel.parker](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tyrel.parker](https://forum.inductiveautomation.com/u/tyrel.parker)\
**Post date:** [June 17, 2021, 7:30pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/3 "2021-06-17T19:30:13Z")

</div>

2/16 as an int should be 0, so I should end up with ns=1;s=[PL\_STACKER]PL\_Stacker.Alarm[0].2  
which is the intention.

But what you’re saying is that the parameter division is not doing integer division?

But if that is the case then why doesn’t the expression testing tags that I created evaluate either?

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 7:46pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/4 "2021-06-17T19:46:55Z")

</div>

> [@tyrel.parker](#):
>
> But if that is the case then why doesn’t the expression testing tags that I created evaluate either?

Apologies, I was incorrect, I got confused with `Bad_NotFound`. In this case it is because expression language is used for expression tags so it should be `{POS}/16`.

The OPC tag uses 'formatted string' to form the path, so `{POS/16}` is valid.

Just setting up a quick test to support the theory, edit incoming shortly.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 17, 2021, 7:49pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/5 "2021-06-17T19:49:30Z")

</div>

The expression language is completely different to the basic parameter expression language. In the expression language, `{stuff}` tries to read stuff as a tag. It doesnt see stuff as a udt parameter you're trying to use. Have you tried your parameter expression inside the opcitempath?

> [@tyrel.parker](#):
>
> The alarm configuration with the parameter math.  
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/9689c6a11c68fa2ecfa1ef50f754202d3fc5f719.png)

What do you mean by 'alarm configuration'? Where is this expression used?  
If this is in an alarm attached to the 'Alarm' tag as part of the set point's expression, you need to use the expression language to manipulate the value of the tag, you can't read the value of another OPC item

---

<div class="post-metadata">

**Author:** ![tyrel.parker](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tyrel.parker](https://forum.inductiveautomation.com/u/tyrel.parker)\
**Post date:** [June 17, 2021, 7:55pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/6 "2021-06-17T19:55:55Z")

</div>

I believe you are correct. I did some additional testing and that is the problem.It evaluates correctly if I take out that division.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/9/d9dc6fcd614a4d00ff5e9a47434dfe33262f0325.png)

I assumed it would do int math since they were both ints and it does not. I even attempted to use a different parameter using the math and put it into an int parameter to use, but it still returns floating point.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/4/b4498f2e5481cf66cee0af3e312ed100de4223f0.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1acba9c378dcd8ea2f8d665e68a21a28b7d64df0.png)

---

<div class="post-metadata">

**Author:** ![tyrel.parker](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tyrel.parker](https://forum.inductiveautomation.com/u/tyrel.parker)\
**Post date:** [June 17, 2021, 7:58pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/7 "2021-06-17T19:58:36Z")

</div>

Yes I have tried. That is the image that you have referenced.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a264ef0f5debbce9672275976b90e0274784ba1b.png)  
That is the expression of the OPC path for the Alarm tag.

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/8 "2021-06-17T19:59:49Z")

</div>

Yep, got the same result:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d1f63e842220ef5a7973e147a722c70b2e94379b.png)

Even when dividing by 1 to get an integer it seems to return a float.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 17, 2021, 8:03pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/9 "2021-06-17T20:03:03Z")

</div>

Seems like a good feature request to add basic type casting into the language

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 8:03pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/10 "2021-06-17T20:03:52Z")

</div>

I just thought there is formatting! One sec, I’ll get an example.

---

<div class="post-metadata">

**Author:** ![tyrel.parker](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tyrel.parker](https://forum.inductiveautomation.com/u/tyrel.parker)\
**Post date:** [June 17, 2021, 8:05pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/11 "2021-06-17T20:05:28Z")

</div>

I thought about that also, but I couldn’t figure out how to format it without the .0 after the number.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 17, 2021, 8:06pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/12 "2021-06-17T20:06:41Z")

</div>

> To format a value, use the form {ParameterName|format}. The format pattern is the same as that used for the numberFormat expression function. In short, "0" can be used to require a digit, and "#" can be used for optional digits. ie: ##0

I forgot about this @matthew.ayre. Shows how often I use parameter expressions haha

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 8:08pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/13 "2021-06-17T20:08:28Z")

</div>

```auto
{PATH}.Alarm[{POS/16|#}].{POS%16}

```

Should work

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [June 17, 2021, 8:10pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/14 "2021-06-17T20:10:23Z")

</div>

I know the feeling 😆, you mentioning type casting stirred the correct neurons into place 🙂

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [May 25, 2022, 1:32pm UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/15 "2022-05-25T13:32:42Z")

</div>

are you sure I try and this does not work for me…  
what I see:  
{PATH}.Alarm[{POS/16|#}].{POS%16}  
if pos is \<=8 the result is 0  
if POS \> 8 the result is 1 …

I already make another discussion but I think is better to reopen this  
[https://forum.inductiveautomation.com/t/udt-parameters-division/59989](https://forum.inductiveautomation.com/t/udt-parameters-division/59989)

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [May 26, 2022, 9:16am UTC](https://forum.inductiveautomation.com/t/udt-parameter-math-is-not-evaluating-correctly/47911/16 "2022-05-26T09:16:23Z")

</div>

Hi @stra, this _was_ working from what I remember 😅. Looking at the date, I think it would have been tested in 8.0.x, what version are you using? Something could have changed in 8.1.x…
