LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rounding in LABVIEW

Solved!
Go to solution

Hello guys ,i am taking an input number from user and then i enter this input to a formula express block that contains this equation output=(input*255)/5 . We know that according to LABVIEW convention in rounding number that is halfway between two integer values , it rounds this number to the nearest even number . This means that if the number is already even , for example 178.5 the rounding will be 178 !! but if it is 177.5 , the rounding will be 178. So how to solve this rounding problem with even numbers ?

0 Kudos
Message 1 of 12
(5,752 Views)

@Ahmed11 wrote:

So how to solve this rounding problem with even numbers ?


What "problem" are you trying to solve? What result do you expect instead?

0 Kudos
Message 2 of 12
(5,738 Views)

I am expecting 179 not 178

0 Kudos
Message 3 of 12
(5,735 Views)
0 Kudos
Message 4 of 12
(5,722 Views)

I am trying to solve the rounding problem . I am expecting 179 not 178 , when the input is 3.5. Thank you

0 Kudos
Message 5 of 12
(5,719 Views)

Because i am doing a analog to digital converter using lab view ( 8 bits analog to digital converter ) . So when i calculate the level of quantization i need to round it to the nearest integer . This is causing a problem for voltage values like 1.5 and 3.5 . Thank you

0 Kudos
Message 6 of 12
(5,718 Views)
Solution
Accepted by topic author Ahmed11

Bankers rounding is the default mode for IEEE 754 (see also), because if you would always round the x.5 up, you are creating a slight bias on average.

If you only have 8 bit resolution, you need to deal with certain limitations, and rouding is probably not the major issue. So you have 256 possible values. What is the voltage range you are trying to cover?

 

You can easily implement any kind if rounding you want (again, see here for the formulas). Since the possible values are so limited, you can even create a lookup table with 256 DBL and use the U8 value to index into it.

Message 7 of 12
(5,684 Views)

Thank you very much !

0 Kudos
Message 8 of 12
(5,642 Views)

Dear altenbach , i am facing a new problem . As you know , i have used the formula (input*255/5) to convert to digital, then i have used digital to binary avi to convert this digital value to 8 bits.

The problem here is the data type mismatch between my output from the formula, which is a double data type and the input of the avi which is a digital data type, so how to solve this problem ? Thank you in advance

0 Kudos
Message 9 of 12
(5,619 Views)

You can use the To Unsigned Byte function found in the Numeric->Convserion palette.  Do this after your rounding.


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
0 Kudos
Message 10 of 12
(5,593 Views)