# Casting in expression

**URL:** <https://forum.inductiveautomation.com/t/casting-in-expression/87633>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [March 20, 2024, 3:19pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633 "2024-03-20T15:19:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 20, 2024, 3:19pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/1 "2024-03-20T15:19:28Z")

</div>

I am trying to cast a tag (float)value to a string inside of an expression within my component. If there is a null value, then the value should display "N/A". I am wrapping my value in the toStr() function to convert the value first. Then I have tried using both != None and None in my expression and I am getting 0.00 for the values still. Can anyone provide suggestions on how to resolve this?

//None  
if( toStr({PouringFurnaceStatus\_HWS\_DISA.ATAS\_SIe.value}) = None,  
"N/A",  
{PouringFurnaceStatus\_HWS\_DISA.ATAS\_SIe.value}  
)

// Not None  
if(toStr({PouringFurnaceStatus\_HWS\_DISA.ATAS\_SIe.value}) != None,  
{PouringFurnaceStatus\_HWS\_DISA.ATAS\_SIe.value},  
"N/A"  
)

---

<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:** [March 20, 2024, 3:22pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/2 "2024-03-20T15:22:23Z")

</div>

Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [March 20, 2024, 3:23pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/3 "2024-03-20T15:23:11Z")

</div>

Try using the `isNull()` expression function, and use it _before_ you convert it to a string.

Here's a link to more info on this function:

> **[isNull | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/logic/isNull)**
>
> Tests to see whether or not the argument value is null

You can also format your float while casting it to a string using the `numberFormat()` function:

> **[numberFormat | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/string/numberFormat)**
>
> Returns a string version of the number argument, formatted as specified by the pattern string.

```auto
if(
	isNull({PouringFurnaceStatus_HWS_DISA.ATAS_SIe.value}),
	"N/A",
	numberFormat({PouringFurnaceStatus_HWS_DISA.ATAS_SIe.value}, "#,##0.0")
)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/5 "2024-03-20T15:26:35Z")

</div>

Actually, the expression language accepts `null`, `None`, and `none` as a null constant.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 20, 2024, 3:28pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/6 "2024-03-20T15:28:41Z")

</div>

The expression would be:

```auto
coalesce(toStr({PouringFurnaceStatus_HWS_DISA.ATAS_Sle}),"N/A")

```

Or if you wanted to also format it as @Brandon_Peterson says you could do:

```auto
coalesce(numberFormat({PouringFurnaceStatus_HWS_DISA.ATAS_Sle}, "#,##0.0"),"N/A")

```

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 20, 2024, 6:41pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/7 "2024-03-20T18:41:48Z")

</div>

> [@lrose](#):
>
> `coalesce(toStr({PouringFurnaceStatus_HWS_DISA.ATAS_Sle}),"N/A")`

I tried that too but im still getting 0.00 as the value that is being returned...

---

<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:** [March 20, 2024, 6:50pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/8 "2024-03-20T18:50:41Z")

</div>

Can you show us a (nicely cropped) screen shot of your tag as it appears in Tag Browser along with the binding editor screen showing the Binding Preview results at the bottom.?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 7:14pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/9 "2024-03-20T19:14:11Z")

</div>

And where you're using it on this component?  
Vision properties are strongly typed, so you can't return a string value from a float property.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 20, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/10 "2024-03-20T19:23:53Z")

</div>

> [@lrose](#):
>
> `coalesce(toStr({PouringFurnaceStatus_HWS_DISA.ATAS_Sle}),"N/A")`

I tried that too but im still getting 0.00 as the value that is being returned...

Ahhh....I just realized that whoever created the template used numeric labels, so this is more than likely why I cant cast the float values to a string.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 20, 2024, 7:36pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/11 "2024-03-20T19:36:09Z")

</div>

> [@Aisha\_Shiddat](#):
>
> I tried that too but im still getting 0.00 as the value that is being returned...

Remember that 0 ≠ NULL. As 0 is a valid value for a float, and coalesce is specifically looking for NULL.

If you want 0 to be printed as "N/A" then that expression would be:

```auto
if(
    {PouringFurnaceStatus_HWS_DISA.ATAS_Sle} == 0,
    "N/A",
    NumberFormat({PouringFurnaceStatus_HWS_DISA.ATAS_Sle},"#,##0.0")
)

```

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [March 20, 2024, 8:11pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/12 "2024-03-20T20:11:14Z")

</div>

Ive tried everything I know and I am still not able to cast the value.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 20, 2024, 8:13pm UTC](https://forum.inductiveautomation.com/t/casting-in-expression/87633/13 "2024-03-20T20:13:38Z")

</div>

Well, if the component you are using the expression on is actually a NumericLabel, then even if you did cast it to a string, it would just try to cast it back to a float again.

Put the expressions on a standard label and then see what happens.

If you're still not able to get it, then provide the information requested by @Transistor and @paul-griffith
