# Limit digit/character count of number/string on a label

**URL:** <https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 30, 2025, 4:24pm UTC](https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740 "2025-04-30T16:24:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BigByte](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@BigByte](https://forum.inductiveautomation.com/u/BigByte)\
**Post date:** [April 30, 2025, 4:24pm UTC](https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740/1 "2025-04-30T16:24:11Z")

</div>

I might just be bad at searching, but I don't see any results on whether this is possible or not. Doesn't say how in the user manual.

My goal is to display a number on a label, and I don't want to show any digits over the thousands place, and I only want to show 1 decimal place if needed. I would expect to do something like `numberFormat({tag}, "###0.#")`. This works for the decimal place (truncating it), but it doesn't seem to truncate the whole digits. Like, if my number is `54321.89`, I want to display `4321.9`, but it's displaying `54321.9`. I know how I would do this in a script, but is there any way to do it in an expression?

Also, it seems like .5 rounds down (so 0.85 rounds to 0.8 instead of 0.9). Is there any way to change this?

---

<div class="post-metadata">

**Author:** ![Simon\_Hathout\_Willar](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Simon\_Hathout\_Willar](https://forum.inductiveautomation.com/u/Simon_Hathout_Willar)\
**Post date:** [April 30, 2025, 4:51pm UTC](https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740/2 "2025-04-30T16:51:14Z")

</div>

You could do something like  
`{tag} % 1000` using modulus to trim down the upper digits

EDIT: should be %10000 if you want the thousands place, oops

---

<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:** [April 30, 2025, 5:00pm UTC](https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740/3 "2025-04-30T17:00:43Z")

</div>

> [@BigByte](#):
>
> it seems like .5 rounds down

That's standard for any rounding function that I've come across. There are two good reasons:

1. It makes it easy to use a function like `int({tag} + 1 / 2}` either mentally or in a script. (This will round to the nearest integer and 1.5 would round to 2.)
2. When visually rounding the numbers 1.49999, 1.50000, 1.500001 to the nearest whole number you only have to read the first decimal place. If 1.500000 was to be rounded down and 1.5000001 up, then you would have to read to the end of the number - just in case.

I've read that some bankers practice was to round to the nearest even number. This would cause half of the x.5 roundings to round up and half to round down and, hopefully, reduce the error in the sum of all the roundings. See [Bankers’ Rounding | Fabulous adventures in coding](https://ericlippert.com/2003/09/26/bankers-rounding/).

If you want it to round up then inject a little offset.

```python
numberFormat(
	({tag} + 0.00001) % 10000, 
	"###0.#"
)

```

---

<div class="post-metadata">

**Author:** ![BigByte](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@BigByte](https://forum.inductiveautomation.com/u/BigByte)\
**Post date:** [May 1, 2025, 1:26pm UTC](https://forum.inductiveautomation.com/t/limit-digit-character-count-of-number-string-on-a-label/105740/4 "2025-05-01T13:26:46Z")

</div>

I don't know why I didn't see this before, but I can just use the `right()` function. So if I want 1 decimal place and 4 whole digits (with the decimal point), I can do the following, which will convert 12345.67 to 2345.7

```python
right(
    numberFormat(
        {tag}, "0.0"),
    6)

```

This will make it a string, which is fine for displaying. But if I needed it as a number for some reason, I could put all that inside the `toFloat()` function.
