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

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?

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

1 Like

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.

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

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