# Expression tag syntax

**URL:** <https://forum.inductiveautomation.com/t/expression-tag-syntax/5174>\
**Category:** Ignition\
**Created:** [September 20, 2012, 7:42pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174 "2012-09-20T19:42:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 7:42pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/1 "2012-09-20T19:42:37Z")

</div>

this expression works perfectly  
toFloat({[.]1\_00})/100

but is the syntax for this expression correct?  
if ({[.]1\_00},\>1)  
toFloat({[.]1\_00})/100

???

the tag i am converting to a float, changes back to “0” as soon as ignition reads it, and i am trying to prevent the converted float from being set back to “0” so i was thinking if the tag that the expression is \>1 then go ahead an convert, otherwise maintain your previous converted value.

by the way, the tag i am reading will never be less than 50.00

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 20, 2012, 8:29pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/2 "2012-09-20T20:29:29Z")

</div>

No the expression will be something like:`if({[.]1_00}>1, toFloat({[.]1_00})/100, {[.]1_00})`

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 8:40pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/3 "2012-09-20T20:40:29Z")

</div>

when i do it that way, i get a red “x” on the corner of my tag

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [September 20, 2012, 8:57pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/4 "2012-09-20T20:57:22Z")

</div>

Just talked to you on the phone about your issue. Post the outcome here when you get a chance.

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 9:00pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/5 "2012-09-20T21:00:20Z")

</div>

same results, even when i select the tag with insert tag icon method

if({[.]1\_00}\>1, toFloat({[.]1\_00})/100, {[.]1\_00})

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 20, 2012, 9:05pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/6 "2012-09-20T21:05:09Z")

</div>

You still get the red error. If it is a tag right click on it and hit the tag diagnostics and let us know the output.

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 9:06pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/7 "2012-09-20T21:06:47Z")

</div>

RuntimeException: Type mismatch in operation ‘Greater Than’: expected ‘Number’, found ‘String’

Ignition v7.5.3 (b1163)  
Java: Sun Microsystems Inc. 1.6.0\_31

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 9:07pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/8 "2012-09-20T21:07:40Z")

</div>

i am converting a string to a number…if that matters

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 20, 2012, 9:14pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/9 "2012-09-20T21:14:59Z")

</div>

So the “1” immediately after the greater than sign is implicitly/explicitly a string? If so, that needs to be changed to some sort of number (float, int, etc).

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 9:22pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/10 "2012-09-20T21:22:23Z")

</div>

the tag’s value that this expression tag is looking at is a string value. it is either 000000 for zero or maybe 003400 to represent 340.00

the expression work just fine when only  
toFloat({[.]1\_00})/100  
is used to convert the string to a float.

the problem i am trying to work around is that after the device recognizes that the string has been read, that register gets set back to 000000, and i want the expression tag to maintain the numerical value until it recieves another number greater than 000000 to convert, not reset back to 000000 like the actual device’s tag.

so i was thinking it wouldn’t reset…or convert the string to a float, if the string it was trying to convert is larger than 1

---

<div class="post-metadata">

**Author:** ![seancourtney](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@seancourtney](https://forum.inductiveautomation.com/u/seancourtney)\
**Post date:** [September 20, 2012, 9:26pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/11 "2012-09-20T21:26:32Z")

</div>

i think if i change the first tag to int4 instead of string this may work, my red x has disappeared.

i will test and report my results, but the red “x” is now gone

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 20, 2012, 9:41pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/12 "2012-09-20T21:41:04Z")

</div>

You can leave the original tag as a string if you like, and then cast the string into a float when using the expression. If you enter 001100, it will convert it to 1100 when using toFloat. For example:

```auto
if(toFloat({[.]1_00})>1, toFloat({[.]1_00})/100, toFloat({[.]1_00}))
```

Would return 11 if the original tag was 001100 (i.e., 1100).

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 20, 2012, 10:02pm UTC](https://forum.inductiveautomation.com/t/expression-tag-syntax/5174/13 "2012-09-20T22:02:15Z")

</div>

This isn’t related to your expression, but it is relevant. I noticed you said that the value you’re reading resets to zero after being read.

You’re going to want to create a scan classes that uses polled reads instead of subscriptions and make sure the SQLTag(s) for these value(s) that reset belong to this scan class.

Otherwise you’re destined for a world filled with heartbreak, pain, and missing values.
