LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

truncate signal value

hello everybody, i need help, i am working in a temperature control and in a one section of the VI i obtain a signal value like this "0.875199" but i need truncate that value and get something like "0.87" only two cifres, please hel, i had tried with a conversion to fixed point but sincerely i do not understand that function

 

0 Kudos
Message 1 of 12
(6,819 Views)

Hi Jorgais,

 

multply by 100, round, divde by 100. (Using floating point math you will introduce rounding errors in the last step.)

Or format this number to string using "%.2f" as format string…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(6,814 Views)

Do you want to round, or truncate? In order to round in LabVIEW, you need to multiply by a factor of 10 to the number of decimal places you want, round to the integer value, and then divide by the factor again.

RoundWeGo.PNG

 

If you're just trying to display the number to certain decimal places, just format the indicator to show to 2 digits of precision. (Right-click > Display Format)

Display2.PNG

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 3 of 12
(6,812 Views)

To follow up on James' question, "Do you want to round or truncate", I'm sure you realize James is showing you the "round" solution by using LabVIEW's "round to nearest integer" function.  If you want to truncate, you need to use "round toward -infinity" (think about what you want "truncate" to do for negative numbers -- do you want the integer "below" or the integer nearest to 0?).

 

Bob Schor

0 Kudos
Message 4 of 12
(6,794 Views)

And, to complicate things further... Either rounding or truncating by the methods already described may not result in a value which is exactly 0.87. This is because of the way numbers are represented in binary in the computer. A value like 87/100 is an infinitely repeating fraction when expressed in binary.

 

Place a numeric control on the front panel. Set Display Format to Floating Point, 18 Significant digits, and uncheck Hide trailing zeros. Then enter 0.87 into the control. The result is: 

 

Almost 0.87.png

 

Lynn

0 Kudos
Message 5 of 12
(6,773 Views)

If you are trying to see if two double precision numbers are "equal" to a certain extent, a common method is to subtract them, take the absolute value, and check if it is less than some threshold.

 

0 Kudos
Message 6 of 12
(6,764 Views)

Thanks, Lynn -- even we "more experienced" programmers sometimes get confused between how the numbers (can be)(are) displayed to us and what the computer is really dealing with.

 

BS

0 Kudos
Message 7 of 12
(6,762 Views)

hey, thanks evebody to take it time for answer, let me explain a part of my project:

Dibujo.JPG

the first DAQ assistant obtain a voltage that is proportional of the current temperature (i am working with a thermocouple type K) but that value has noise i am trying "clean" the signal with the filter, after that i need obtain a value only with two digits 0.00 , because i need a signal very stable, maybe you have any idea to process my signal.

0 Kudos
Message 8 of 12
(6,744 Views)

Cutting off your extra decimal places won't make your signal more stable. That's not how it works, you're just cutting off some of your info. You could implement a running average of your data so that the display doesn't jump around.

 

Check out this Mean PtByPt looping with a random number between 0 and 1. Play around with it a little bit. If you adjust the sample length, the higher it gets, the more stable the graph becomes (centerred around 0.5).

Mean PtPt.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 12
(6,739 Views)

indeed if you want to show 0.875199 as 0.87 you should not use  nearest round 
you have to use Round Toward -Infinity Function not nearest
also if you have minus temperature and want to round it toward 0
for example - 0.875199 to - 0.87 you should use some thing like this code temp.jpg

Message 10 of 12
(6,724 Views)