03-03-2016 09:10 AM
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
03-03-2016 09:15 AM
03-03-2016 09:17 AM - edited 03-03-2016 09:23 AM
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.
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)
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
03-03-2016 09:34 AM
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
03-03-2016 09:59 AM
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:
Lynn
03-03-2016 10:07 AM
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.
03-03-2016 10:08 AM
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
03-03-2016 10:33 AM
hey, thanks evebody to take it time for answer, let me explain a part of my project:
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.
03-03-2016 10:38 AM - edited 03-03-2016 10:48 AM
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).
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
03-03-2016 11:00 AM - edited 03-03-2016 11:16 AM
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