How to limit the # of decimal points displayed in a floating point of a text area

Is there a simple configuration that I’m missing? Our floats are coming in with 8+ decimal points, and I would like to limit what the user sees in the Text Area to 1 or two points only. Thanks

You need to format these if used in a text field using numberFormat(number, format)
e.g. numberFormat(toFloat(tag(Root Container.DeviceTagPath) + '/PV'), '0.0')
numberFormat(1.231452, '0')

Used tag to demonstrate that you first need to convert the result to a number to use with numberFormat

I am pretty new to Ignition and Perspective but I had the same issue, I added a transform on the tag binding and it worked for me.

1 Like

The transform works. Thanks

nminchin,

Can you tell me what is wrong with my procedure to get this conversion? I highlighted where the tag is in my database so you can see DeviceTagPath.

Can you explain to me - since I’m displaying a tag right out of the tag browser, and it isn’t a parameter that is being passed from another view, I thought that view.rootContainer would be the right way to point the argument of the function. Thanks for helping me better understand how this object traversal works.

You don’t need to use the tag() function or the view’s root container at all, at least in your example. tag() is used to create a dynamic reference to a tag within an expression - say you had a view parameter like ‘MachineNumber’, and a tag structure with UDTs for Machine 1, 2, 3, etc. You could then use something like:
tag("[default]Factory 1/Machines/" + {view.MachineNumber} + "/PV")

Within Ignition’s expression language, the curly braces already specify “this is a dynamic reference” - so if you have the exact path to a tag, just put it inside curly braces:
numberFormat(toFloat({[default]Compressor Stations/Compressor Station 1/FOUNDATION COMPRESSOR STATION/PV}), "0.0")

So expanding on this idea, I have a large amount of data in a table that I need to use the toFloat function on. I am having a little difficulty deciding the best way to pull the specific tags out of my nested for loop in the 2D array that builds this table.

The desired result is to modify the scripting so that it rounds our floating point values to two decimal points.

Is there a way to work this ‘if statement’ to round my parameter based on if the element in the header list is ‘BATTERY VOLTAGE’?

You should never rarely ever format your data at the source. You should format the data in the display, in this instance you can format the display using the columns numberFormat property.

https://docs.inductiveautomation.com/display/DOC80/Perspective+-+Table

Scroll down until you get to Properties -> columns, 'click to see columns properties -> numberFormat

The only problem with your approach is that we had to convert the value of the tag data to a string as you see in my script:


So formatting the data in the table wont work

Just a stupid question but does row 26 have valid data in it or is it NULL? I have come across this error before and it took me a little while to understand why I was getting it on just the one row and not the others.

Something to think about.

Why do you need to convert the value to a string?

In any case though, you can override the columns render property to be number instead of auto.

The reason we had to convert to string is probably because we have some tags that are polling bad values since we don’t have the drivers configured yet.

So, I’ve configured the column in my tag to render numbers and set the format to four decimal places, and I’m still not getting any decimals shaved off the number?

OK so if it must be a string you can script the decimal places out of it;

run this in the script console:

string_example = "123.4567"
dec = string_example.split(".")
print dec[0]+"."+dec[1][:2]

Does your field value match exactly the column name in the data? It doesn’t look like it, as field names cannot have space characters.

e.g. ‘population’
image

image

FYI the header title text itself is defined in the header.title property:
image

This is a vitualized dataset, we used a two dimensional array to build it.

The black box that pops up when I mouseover says the field should also reference the element and key for an array.

The header is two words, BATTERY VOLTAGE.

This is the two dimension array script that generates the virtual dataset:
tags =

for i in range(len(meterList)):
	vals=[]
	vals.append(meterList[i])
	for item in headerList[1:]:		
		param = ("[default]Orifice Meters/" + meterList[i]+'/'+str(item))
		vals.append(str(system.tag.read(param).value))
	tags.append(vals)

I think it should be the array index in your case, so just field:1

Strange, when I disable “visible”, the very last column dissapears on the far right of the table. Also, field:1 doesn’t seem to do the intended effect on the column.

Try different field names, but first change your header.title to something unique so you can see when the header changes in your table (then you’ll know you have the field name correct). Maybe read how to define in in the user manual as well

OK. So I’ve learned how to render columns with this table, but for some reason I can successfully render the date and time tags, but the number seems to have no effect.

I’ve tried it myself, and it appears to be due to your strings. I would modify your script to stop converting the tag values to strings. you can use a try/catch if necessary.

Also, to increase efficiency and speed, bulk read your tags instead of reading them in one-by-one. I would just bulk read the tags in each of your meters and still recurse through each meter, but you could also bulk read all of your tags for all meters at once, it just wouldn’t be as nice to pull out, but would be the most efficient.