From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to round a result before reported

Solved!
Go to solution

Hello,

my measurement teststeps return results like 1,7267326467267236423 and only the first two values after the comma are interesting.

How can i set a Postexpression to round the result that ist put in Step.Result.Numeric before it is returned and displayed/reported?

Thx

0 Kudos
Message 1 of 8
(4,911 Views)
Solution
Accepted by OnlyOne

You don't need a post expression necessary. I'm assuming you are using the Numeric Limit Test. Under the Limits tab, there's the Numeric Format cell, click on it and choose custom. Go into the Format box at the bottom and put "%0.2f". This will display the value and the limits in the report as 2 digits after the decimal place.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 2 of 8
(4,907 Views)

Hmm, i clicked to early 🙂

This changes are only valid inside of TestStand and TestStand reporting.

The value that is delivered via API to the OPUI is still the original value...

0 Kudos
Message 3 of 8
(4,897 Views)

That would make most sense. When you report or display the data is when you can cut off digits of precision or round. We know for certian at that point we don't need the accuracy.

 

While the data is still 'live' and can potentially influence other data (using it subtract from another value, like an offset), TestStand should use all available digits of precision.

 

I'd suggest rounding your value in the Operator User Interface if you want to only display the 2 digits of percision.

 

 

The only other method I can think of is to create your round function.

 

"Step.Result.Numeric = Round(Step.Result.Numeric*100)/100"

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

0 Kudos
Message 4 of 8
(4,891 Views)
Solution
Accepted by OnlyOne

While Round will do what you want, it has a flaw in that it can false pass or false fail for values that are just outside of the precision of your limit you are rounding to unless you use a multiplier/divisor that is at least 10x greater than the precision you are interested in. So using PI, and looking for a precision of 3 digits, the following would false pass:

 

Step.Result.Numeric = PI,

Step.Result.Numeric = Round(Step.Result.Numeric*1000)/1000

 

For limits 3.140 <= x <= 3.141

 

As Round would set Step.Result.Numeric = 3.141, which is not correct (it should round to 3.142)

 

while:

 

Step.Result.Numeric = Round(Step.Result.Numeric*10000)/10000

 

would properly pass with the same limits.

 

An alternative option is to use the following:

 

Step.Result.Numeric = Val(Str(Step.Result.Numeric, Step.Limits.Low.NumericFormat))

 

so that the result is automatically properly rounded and truncated to the precision desired.

 

I hope this helps.

 

Message 5 of 8
(4,880 Views)

Thx for the solution. Looks very good.

Is there a callback to do this for all existing numeric limit tests at once?

Or do i have to do it manually for each step separate?

Thx

0 Kudos
Message 6 of 8
(4,840 Views)

HI OnlyOne,

 

No unfortunately - See The Execution section of the TestStand Reference Manual, which has a Step Execution order-of-events list. There's no callback between the Module call, the Post Expression and the Status Expression evaluations. In theory you could create a custom step and add a Post-Step substep that could do this, but that's an advanced technique that I'll leave for someone who's done substep development like this.

 

Hope that helps.

 

-Jack

0 Kudos
Message 7 of 8
(4,813 Views)

I've implemented this before in the SequenceFilePreStep callback although it does add overhead. You have to weigh in the added development time to copy/paste the rounding call into numeric tests versus the added overhead if you are running thousands of numeric limit tests in a row each time.

 

Essentially you should check that Parameters.Step.StepType.Name == "NumericLimitTest", and that rounding isn't already applied. Then you can add Jack's suggested text to the datasource (with whitespace) with the expression: Parameters.Step.DataSource = "Val(Str(\n" + Parameters.Step.DataSource + "\n,Step.Result.Numeric.NumericFormat))"

0 Kudos
Message 8 of 8
(4,030 Views)