LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rounding off to nearest decimal point

Solved!
Go to solution

i have these values

 

35.2
35.3
35.4
35.5
35.7
35.8

35.9

36.0

 

i am looking for indexes closet 35.74 in my array. (which is index 4.)

 

i used the "round to nearest" function and it gave me 36.

which is index 7.

 

what other ways to get the right index?

 

 

 

 

0 Kudos
Message 1 of 18
(7,935 Views)

?

I guess you can just take the absolute value of the difference and the smallest one is the closest one?

 

I actually have no idea what you are trying to do.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 18
(7,929 Views)

i want to find 

the index closest to

 

value 35.74

 

just by looking at it. it should be 35.7 or 35.8

i tried using the round to nearest function and it rounded out to be 36.00

 

how can i make it so that i can get 35.7?

 

0 Kudos
Message 3 of 18
(7,899 Views)
Solution
Accepted by super_saiyans

Try Threshold 1D Array.

 

Threshold.png

 

It should be noted that you'll need a sorted array as in your example.  If that's just a simple explanation for a larger context, you may need something more sophisticated.

--
Tim Elsey
Certified LabVIEW Architect
Message 4 of 18
(7,883 Views)

You will always have some difficulties with rounding to a specific number of digits after the decimal point because of the way numbers are represented in binary. When expressed in binary 0.1 is an infinitely repeating expression. Regardless of the display the internal representation of the number always uses the maximum resolution for the data type (8 bytes for DBL).

 

So you need to be very careful to define exactly what you  want. If you have an array of values (regardless of the way they are displayed) Then you can find the closest to a Test Value by subtracting Test Value from the array and finding the minimum of the absolute values of the differences.

 

Note that in the image below the same values are in Array and Array 2 with the display on Array 2 set for 20 siginficant digits. 

 

Lynn

 

find closest.png

Message 5 of 18
(7,876 Views)

thanks!!

both method works!!

elset191,

thank you, but my data is not sorted so it wont work. but the example worked.

thank you!

0 Kudos
Message 6 of 18
(7,860 Views)

Really I should get an honorable mention (i.e., kudo) for being the first one to mention the method you chose as the solution.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 18
(7,833 Views)

lol.

THANK YOU BOTH

 

Message 8 of 18
(7,786 Views)

See Here Also

Seen Here

 

Obviously, X should be a Float but I was too lazy to fix it


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 18
(7,774 Views)

One other comment about rounding.  LabVIEW uses banker's rounding which takes any value that is dead on 0.5 and will round it to the nearest even integer.  Generally in school we would have learned that 0.5 would be rounded up.

 

So nearest even integer may or may not be what you are looking for.

 

 

0 Kudos
Message 10 of 18
(7,767 Views)