LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

split a decimal number into 2 numbers

HI
 
i have a small Problem and i don't know how to solve it , maybe you can help me to find the error.
In this e_mail you will find attached a Labview version 6.0.
The aim of this Program is to split a decimal number into 2 numbers , the first number is the one befor the comma and the second number is the one after the comma. For example: 9.58 the first number will be 9 and the second is 58 .
My problem is that this program works with all numbers except the odd numbers like for example 9.00, the program split it into 8 and 1 and not into 9 and 0 but if i write 8.00 it split it correctly into 8 and 0
 
Thanks
0 Kudos
Message 1 of 17
(8,975 Views)
The problem you run into is a specific behavior of LabVIEW when converting DBL/SGL to INT.
Pls check out the following KB for additional information on this specific issue: How Does LabVIEW Round and Coerce Values?

I've attached a VI which shows the way...

Thanks,
ThSa
0 Kudos
Message 2 of 17
(8,966 Views)
Why not just use the Quotient & Remainder function?



B-)


Message Edited by LabViewGuruWannabe on 11-18-2007 01:29 PM
Message 3 of 17
(8,962 Views)
Good point, but the indicators does have INT representation 🙂
0 Kudos
Message 4 of 17
(8,959 Views)
Yes, of course. To convert the remainder to an integer, multiply by 1000 and convert.




Message Edited by LabViewGuruWannabe on 11-18-2007 01:48 PM
0 Kudos
Message 5 of 17
(8,953 Views)
@spam@
Good point, but what happens when the precision gets changed -> property node?
0 Kudos
Message 6 of 17
(8,947 Views)
That wasn't a condition of the original post. Smiley Wink

However, if the precision is changed, then simply use a control instead of the constant [1000]. If your number of decimal places needs to vary, create a control called "Decimal Places" and use the Power of 10 function for the multiplier.

Of course, you'll want to use a 32-bit integer if you need more than 5 decimal places.



B-)


Message Edited by LabViewGuruWannabe on 11-18-2007 02:13 PM
0 Kudos
Message 7 of 17
(8,937 Views)
@spam@
That code snippet is the one I've expected, excerpt the problem that your code does not guarantee the correct value when running the VI first time (race condition).
Now compare your solution with the "Format into String/Format from String" stuff.

Which one is simpler 🙂
(you get the 1st place for the smartest solution!)




0 Kudos
Message 8 of 17
(8,927 Views)

Since the output is set to I16, I assume we have to allow negative inputs. In this case the above Q&R solution does no work as expected.

I would do something like the following (The original problem had 1000 hardwired so we just want it in milliunits for the fractional part).

Still, we need to be careful about FP issues.



Message Edited by altenbach on 11-18-2007 12:56 PM

Message Edited by altenbach on 11-18-2007 01:04 PM
0 Kudos
Message 9 of 17
(8,920 Views)
Ok,

A) This code I posted is simply an example. Any concerns for precision and race conditions are the responsibility of the designer, as with all programs.
B) Since the original poster did not have his/her code in any loop or have any additional code, I considered it also to be an example, not an entire program.
C) The precision and representation for inputs and outputs were not specified as requirements by the original poster.
D) Your number-to-string-to-number code works fine, and I never said it didn't. I simply posted an alternative.

However, if you want to get picky, what happens with your example if the precision of the Numeric is changed?

B-)
0 Kudos
Message 10 of 17
(8,919 Views)