07-25-2017 11:18 AM
I am trying to round a calculated value. This value can be both positive and negative numbers. I want the posative numbers to round normally (at 0.5, round up to the nearest whole number) and negative numbers to work opposite (-25.5 rounds to -26) and I have not been able to figure it out.
I have attached the current rounding code but when i get a value for locals.offset of -25.5, instead of rounding up (or down really) to -26, it rounds to -25. I understand why it would make sense for this to happen but I have not been able to get -25.5 to round to -26. Would somebody be able to help me out with this?
Solved! Go to Solution.
07-26-2017 04:18 PM
Can you use one of the rounding options? For example, instead of "round(-25.5)", use "round(-25.5,4)". The 4 on the end directs the round function to always go to the nearest integer.
08-02-2017 09:51 AM
Hi,
Use Round(x, 1), as the '1' for the second parameter will always round away from zero. Positive numbers round up, negative numbers round down.
So...
Round(0.5, 1) = 1
Round(-25.5, 1) = -26
I hope this helps,
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
08-02-2017 01:19 PM
but then you run into problems when you have -25.4 or 25.4 and you want to round to -25 and 25 respectively.
I found that the error was in the calculation. By using a calculator or excel, numbers and equation I was using came out to exactly 25.5 but in TestStand it was something like 25.49999999999992300. I didn't see this until I found out how to increase the number of digits shown for a number variable.
It wasn't a TestStand error, it was a calculation error.
08-10-2020 04:46 AM
Hi guys,
i need one solution regarding Range Property,
Instead of 0.5 range, i want 1 range.
example: if our range can be 65. nd if we get 64 means it should show 65 only and in other case if we get 66 means it should show 65 only.
can we do that in teststand.???