# Error using UDT parameter as # of decimal places in Round() function

**URL:** <https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727>\
**Category:** Ignition\
**Created:** [November 20, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727 "2022-11-20T16:45:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Kleiman-Lynch](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Max\_Kleiman-Lynch](https://forum.inductiveautomation.com/u/Max_Kleiman-Lynch)\
**Post date:** [November 20, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/1 "2022-11-20T16:45:13Z")

</div>

Trying to use UDT parameter (an integer called 'Decimals') as the number of decimal places for a round() function to round to. When I just put in an integer, the code works so I know everything else is fine. Something about the way I'm referencing the UDT parameter seems wrong though. (I've tried adding a toINT(), that did not work). Thanks in advance!

Any ideas? I'll include the code and the error below

Update: It actually works as expected the way it is written, despite the fact that it throws that error...  
Just a bug?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/87e0ce6b3191191f855c72ed654d296a943bf651.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/5/555e2e5cb8e707696bf28ba6309d5f0fb97999bd.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 20, 2022, 11:29pm UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/3 "2022-11-20T23:29:08Z")

</div>

Try using the expresson language `tag` function to see what type is being returned.  
[https://docs.inductiveautomation.com/display/DOC81/typeOf](https://docs.inductiveautomation.com/display/DOC81/typeOf)

Tip: post code rather than pictures of code. That way we can copy it into our answers and modify it rather than type it all out again.

---

<div class="post-metadata">

**Author:** ![Max\_Kleiman-Lynch](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Max\_Kleiman-Lynch](https://forum.inductiveautomation.com/u/Max_Kleiman-Lynch)\
**Post date:** [November 21, 2022, 2:00am UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/4 "2022-11-21T02:00:49Z")

</div>

Thanks for the response (and the tip!). That is a helpful troubleshooting function. By using it I found that the tag() function in question is returning a long. But I'm still confused why using toInt() or toInteger() doesn't resolve the error. The expression actually works as expected whether I just use the tag() function or if I use a toInt(tag()) for [decimals] in round(). It just throws that error every time I close or save the Template.

Thanks again!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 21, 2022, 3:19am UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/5 "2022-11-21T03:19:47Z")

</div>

Just to check my understanding, tag1 produces the integer part of the number as a scaled value, and tag 2 produces the decimal part of the value?  
...so if tag1 = 123  
...and if tag2 = 3456  
...then the expected result is round(123.3456) or 123. Am I understanding this correctly?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 21, 2022, 7:10am UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/6 "2022-11-21T07:10:52Z")

</div>

Justin, no, the expression is  
`toStr(round("123.45678", 3))`  
which should return `123.345`.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 21, 2022, 7:26am UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/7 "2022-11-21T07:26:17Z")

</div>

> [@Transistor](#):
>
> Justin, no

Ah, I see it now. Thanks

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 21, 2022, 7:31am UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/8 "2022-11-21T07:31:28Z")

</div>

> [@Max\_Kleiman-Lynch](#):
>
> is returning a long. But I'm still confused why using toInt() or toInteger() doesn't resolve the error

A long datatype is an integer already, so having a decimal is probably the issue. Since you are expecting decimal places, perhaps using the toFloat() conversion would be the correct thing to do in this case:

```auto
toStr(round(toFloat(
{[default]myTags/Scaled_Value}), 
{[default]myTags/Decimals}))

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 21, 2022, 12:37pm UTC](https://forum.inductiveautomation.com/t/error-using-udt-parameter-as-of-decimal-places-in-round-function/66727/9 "2022-11-21T12:37:01Z")

</div>

I'd expect the first tag to already be a float, otherwise there'd be no rounding to do - which looks like is working, despite the error raised.

If entering a constant instead of using a tag value for the decimal part gets rid of the error, then I'm thinking the error comes from the second tag. What are its value and datatype as shown in the tag browser ?
