NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is this number rounded down instead of up?

Solved!
Go to solution

In my TestStand 2019 application the number 0.18325, with 4 decimal digits (format string %.4f), is rounded to 0.1832. I would expect 0.1833,

as indeed happens correctly for 0.18326, ... , 0.18329, since the fifth decimal digit is greater than or equal to 5. Am I missing something? These are my custom number format settings.

format.png

Could anyone help me, please?

Thanks in advance, and best regards!

Alessia

0 Kudos
Message 1 of 5
(1,236 Views)
Solution
Accepted by alessia.lamanna

It would be because it would use Bankers rounding where a number in the middle of two numbers is rounded to the nearest even number.

 

So, anything at x.5 will use this particular case.

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 5
(1,228 Views)
Solution
Accepted by alessia.lamanna

Also note that Banker's Rounding is actually the IEEE recommended rounding due to statistical analysis.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 5
(1,218 Views)

Bankers rounding is only part of the story here and is probably not the correct explanation in this edge case.

 

A format of %.4f is a purely cosmetic property. Assuming the underlying numeric is in DBL representation, the closest number to 0.18325 that can be represented correctly in binary is 0.183249999999999996 and thus will be rounded to 0.1832 in any typical rounding scheme.

 

Where does the value come from?

Message 4 of 5
(1,207 Views)

@altenbach:

This is a limit value for a Numeric Limit Test step, and has been calculated as follows:

0.175+0.003+0.175*0.03

0 Kudos
Message 5 of 5
(1,160 Views)