LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to round with decimals in labview?

I don't understand your message.

 

Besides your VI, can you give more detail on what you are trying to do and why?  Give some examples as to what you are expecting and what answer you are actually getting?  I don't understand your reasoning for why you are doing differently than what was posted earlier in your message.

0 Kudos
Message 21 of 41
(3,600 Views)

There was two points in my message.

 

First one, i modify the .vi of Ian to avoid the problem with the rounded numbers because there were people asking for it.

 

And the second one, was a problem I have comparing two numbers that supposse to be the same, I have already solve it by changing the type of data to single precission float

Message 22 of 41
(3,588 Views)

You haven't explained what was wrong with the rounding of numbers using Ian's method.

 

Of course if you are trying to compare floating point numbers they aren't always going to be equal.  That is the nature of floating point numbers within the binary system of a PC.  The reason converting to single precision worked for you is that you had made the resolution of the number coarser, and probably fell into equality.  It might have worked this time, but I'm sure there are other numbers out there that are going to fail for single precision.

 

One of the rules on PC's is "Don't compare floating point numbers for equality!"

0 Kudos
Message 23 of 41
(3,585 Views)

victorMartinez wrote:

And the second one, was a problem I have comparing two numbers that supposse to be the same, I have already solve it by changing the type of data to single precission float


This is definitely not a valid solution.

0 Kudos
Message 24 of 41
(3,582 Views)
It's working for the numbers I need, for now. How will be the solution?
0 Kudos
Message 25 of 41
(3,568 Views)

When trying to compare for equality with any type of floating point (singles, doubles, extended), you need to compare a range.  The In Range & Coerce function is good for this.


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 26 of 41
(3,556 Views)

How to compare without a range? I need the exact number. What about convert to another type?

 

thank you!

0 Kudos
Message 27 of 41
(3,544 Views)

@victorMartinez wrote:

I need the exact number. What about convert to another type?


In floating point representation (DBL, SGL, etc.) there are no guaranteed exact numbers from a decimal point of view if you have fractional values. They will always be quantized to the nearest possible binary value. For example, 0.1 does not have a binary equivalent unless you use an infinite number of bits.

 

Please explain what you are trying to do. A valid algorithm has already been presented above and if you apply it to both sides of the comparison, you should be fine. What have you tried? What problems did you encounter? Can you attach some typical data that shows the problem?

 

 

Message 28 of 41
(3,538 Views)

Here is what I'm trying to do, it's suppose to be the reading of three sensors, and depending of the position they are and the position I want, they move in one way or the other.

 

I'm also having problems with the reading of the DAQ the second time

 

As you can see the program it's starting. Right now I have problems with the comparation numbers (black circles in the picture) and receiving the data from the DAQ the sencond time (red circle below)

 

Thank you for your interest, and for helping me.

Download All
0 Kudos
Message 29 of 41
(3,524 Views)

Looks like quite a mess.

 

  • For the comparison to work correctly, you need to apply the same transformation also to the inputs from the controls. Currently, you don't. (make it into a subVI for cleaner and re-usable code).
  • The second while loop can only start once the first loop is finished. Right? Are you expectin the two inner loops to run in parallel?
  • The outer while loop has no purpose.
  • You have way too much duplicate code in the case structures. All code that is shared between all cases belong outside the case. Here, only the add or subtract belongs inside the case structure, ebverything else belongs outside.

Sorry, I don't have DAQ, so I cannot look at your configurations.

Message 30 of 41
(3,507 Views)