# \[BUG\] String Format Floats

**URL:** <https://forum.inductiveautomation.com/t/bug-string-format-floats/66375>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [November 10, 2022, 10:42pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375 "2022-11-10T22:42:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 10, 2022, 10:42pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/1 "2022-11-10T22:42:55Z")

</div>

Trying to use string format to format the field width, as well as a floating point number, I've run into a bug.

The tag I'm displaying is a float, but despite that I get a

```auto
IllegalFormatConversionException: f != java.lang.Integer

```

Error when using the tag directly in the stringFormat function.

```auto
"Level: "+stringFormat("%4.1f", toFloat({[default]SCP/Level}))+" ft"

```

Produces the desired result, but

```auto
"Level: "+stringFormat("%4.1f", {[default]SCP/Level})+" ft"

```

Results in the error, but still seems to format it correctly.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2022, 1:06pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/2 "2022-11-11T13:06:21Z")

</div>

> [@amarks](#):
>
> `java.lang.Integer`

What's the data type of the tag?

EDIT: And, what is the input and desired output? You know the drill... 😉

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 11, 2022, 2:44pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/3 "2022-11-11T14:44:04Z")

</div>

> [@amarks](#):
>
> The tag I'm displaying is a float

It's a float tag. I'm trying to constrain the field width so that numbers stay in-line when leading digits are dropped, rather than shifting to the left when the number is shortened (also shifting the unit label of ft.).

Like so:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/8/f8150f28249df203a8e3a9a76c097420d4d8d767.png)  
instead of:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/c/2c1c9963ce5679708e669e3d28b3954bce7cbc56.png)  
(using `numberFormat()`)

Like I said, the formatting still seems to work, but I get the error.  
  
  
This doesn't seem to happen if I add custom properties to the label, bind the tag to that property, and use that property in the expression binding for the text.

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

```auto
"Level: "+stringFormat({Root Container.Label 1.formatString}, {Root Container.Label 1.value})+" ft"

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2022, 4:17pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/4 "2022-11-11T16:17:54Z")

</div>

> [@amarks](#):
>
> It's a float tag.

Apologies for overlooking that.

Seems to work okay for me. v8.1.21.

```auto
stringFormat("Level: %,8.1f ft", {[Test]tag1})

```

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

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 11, 2022, 4:40pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/5 "2022-11-11T16:40:40Z")

</div>

It seems to do the formatting okay for me as well, but I still get the error. And I get the error every time I re-open the window with the binding.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [November 11, 2022, 4:43pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/6 "2022-11-11T16:43:00Z")

</div>

It might be the binding starting to evaluate and passing a null at the beginning. Maybe add a coalesce:

```auto
stringFormat("Level: %,8.1f ft", coalesce({[Test]tag1},0))

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 11, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/7 "2022-11-11T16:45:07Z")

</div>

> [@bschroeder](#):
>
> ```auto
> stringFormat("Level: %,8.1f ft", coalesce({[Test]tag1},0))
> 
> ```

at that point I may as well use the `toFloat()`

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2022, 4:50pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/8 "2022-11-11T16:50:46Z")

</div>

Would be interesting to know why it's seeing an integer though. Is the tag data itself a float or is it scaled? Like 0-1000 scaled to 0-100.0 kind of thing.

Does the error happen on every value change as well as opening the window?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 11, 2022, 4:53pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/9 "2022-11-11T16:53:58Z")

</div>

They're all memory float tags (for the test). No scaling, just straight values.

Looks like it's only when the window first opens.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2022, 4:55pm UTC](https://forum.inductiveautomation.com/t/bug-string-format-floats/66375/10 "2022-11-11T16:55:32Z")

</div>

Ok I was able to reproduce it.
