LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fraction

How do you display your answer as a non-reduced fraction using 3 indicators. 1 for the whole number, 1 for the numerator, and 1 for the denominator.

0 Kudos
Message 1 of 10
(3,097 Views)

Well, that's gonna depend on what "answer" you're referring to.

 

Do you start with both dividend and divisor?  That should be easy.  Or do you start with a single value with digits to the right of the decimal?  That's more complicated.

 

Either way, you'll probably want to make use of the Quotient & Reminder function.  If you start from a single decimal value, you'll want to look into rational approximation.  I'd recommend the Mathscript node if you have it available in your installation.  Otherwise, my link in that thread will lead you to a more brute-force method.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 10
(3,083 Views)

The GCD (greatest common denominator) function is useful too.

 

Depending on the details...

0 Kudos
Message 3 of 10
(3,039 Views)

wiebe@CARYA wrote:

The GCD (greatest common denominator) function is useful too.

 

Depending on the details...


The OP did state "nonreduced", which is you would still have 2/8 instead of 1/4.  Therefore, I think the Quotient & Remainder is all that is needed here.


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 4 of 10
(3,023 Views)

@crossrulz wrote:

wiebe@CARYA wrote:

The GCD (greatest common denominator) function is useful too.

 

Depending on the details...


The OP did state "nonreduced", which is you would still have 2/8 instead of 1/4.  Therefore, I think the Quotient & Remainder is all that is needed here.


If he has a float, what exactly is the non reduced fraction supposed to be? Is "1.040" "1 4/100", "1 40/1000?" or "1 400/10000" or "1 400/100000"? Q&R is only very little help.

 

If he already has a nominator and denominator, how is the Q&R going to help?

0 Kudos
Message 5 of 10
(3,017 Views)

wiebe@CARYA wrote:

If he already has a nominator and denominator, how is the Q&R going to help?


The OP stated they wanted a whole number as well.  So I am left to assume they want something like X = 10, Y = 4, therefore the outputs should be Whole Number = 2, Numerator = 2, Denominator = 4.  So you can just use Q&R to get the Whole Number (Quotient) and the Numerator (Remainder) and then just pass Y as the Denominator.

 

But this is mostly speculation until the OP clarifies, preferably with an example.


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
Message 6 of 10
(3,012 Views)

@crossrulz wrote:

wiebe@CARYA wrote:

If he already has a nominator and denominator, how is the Q&R going to help?


The OP stated they wanted a whole number as well.  So I am left to assume they want something like X = 10, Y = 4, therefore the outputs should be Whole Number = 2, Numerator = 2, Denominator = 4.  So you can just use Q&R to get the Whole Number (Quotient) and the Numerator (Remainder) and then just pass Y as the Denominator.

 

But this is mostly speculation until the OP clarifies, preferably with an example.


That makes sense now.

0 Kudos
Message 7 of 10
(2,997 Views)

Maybe this will be helpful.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 8 of 10
(2,976 Views)

@Kevin_Price wrote:

If you start from a single decimal value, you'll want to look into rational approximation.  I'd recommend the Mathscript node if you have it available in your installation. 

Actually, the Mathscript function might be buggy unless they fixed CAR 702329. See my code here and surrounding discussion. It is trivial to go from the rational approximation to "Number =~ (X + Y/Z)" and display the three values, of course.

0 Kudos
Message 9 of 10
(2,938 Views)

Yikes!   Thanks for the tip.  (Interestingly, I had tested the MathScript funciton briefly and successfully with the same small tolerance of 1.0e-8 that didn't work in your linked example.  The code was still up in a background window, and I fed in the pi constant as input.  The one (of many) "bad" values you illustrated 0.6251 failed for me in LV 2016 too.  I guess it's not a new bug.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 10 of 10
(2,925 Views)