numberFormat info

i’m testing the numberFormat and i used the example on the manual
numberFormat(34.8, “#0.00’%’”)

but i got an error saying

[quote]Traceback (most recent call last):

File “event:mouseClicked”, line 3, in

NameError: name ‘numberFormat’ is not defined

Ignition v7.5.3 (b1163)
Java: Oracle Corporation 1.7.0_05

Why is that?

You’re looking at a function from the expression language in the manual but trying to use it in scripting, which you can’t do.

You might want to look at formatting in Python: … ing-syntax

ok so i did it like this

n = 33.33 n = str(int(n*100))+'%' print n

it worked on the console window, the output was 33%

but when i tried to do it to show on the table all i got was 33, why is that?

How are you using the value in the table? Can you post the entire mouseClicked script?

It would help knowing exactly what you are trying to do.

i’m trying to compute for the oee and i need the output on the table to show the percent sign

a = 8.0/24 availability = str(int(a*100)) + '%' event.source.parent.getComponent("Table").updateRow(0,{1:availability})

Ok, I see. What is the datatype of the availability column in the table? If it is an integer than you will not see the %. In that case you can go into the table customizer and add a suffix or number format on that column.

oh cool i got it.

thanks :smiley:

Hi Kavin,

numberfomat(tag(“topic”+{Parameter Tag}),"#0")

i was trying to execute above expression in Label expression,but its not working.

Please check

@dtamada The error message you would’ve got entering this into an expression binding, “Unknown function: ‘numberfomat’” is your tip that you’ve misspelled the function name:
It’s numberFormat (not numberfomat, missing “r”).

P.S. It’s usually better to start a new topic rather than resurrect a really old one. The original poster was trying to use the expression in scripting (where it doesn’t work).

Hi witman, thanks for the reply

I am using one custom properties.

  1. PLC number

My tag expression is tag(“ PLC1/tag”+{ PLC number}) - it works,


PLC1/tag_1 = 12.0 (Tag type is Float4 )

I want to display only 12 in place of 12.0 in a Label Display

numberformat(tag(“PLC1/tag”+{ PLC number}),"#0") – doesn’t not work.

numberformat({PLC1/tag_1},"#0") – it works

is it possible to write expression in scripting ? if not, how can I achieve above result?

Please suggest, thank you for the support.

tag() returns an object, not a number. Try:

numberformat(toDouble(tag(“PLC1/tag”+{PLC number})),"#0")

As @JordanCClark noted, you’l want to convert the tag object returned by tag() to a number. Also, based on this:

It looks like your first expression (that doesn’t work) is missing an underscore after “tag” in the tag name–try:

numberFormat(toDouble(tag(“PLC1/tag_”+{PLC number})),"#0")

Please, people! Stop recommending the tag() function. It exists for legacy compatibility. Use indirect tag bindings!

1 Like

I was focused on what would keep your expressiong from evaluating, but as @pturmel notes, tag() gives poor performance. A better way to accomplish this would be via an Indirect Tag binding something like this:

Then do the numberFormat on the value you get from the indirect binding.