キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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 件の賞賛
メッセージ1/10
4,278件の閲覧回数

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 件の賞賛
メッセージ2/10
4,264件の閲覧回数

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

 

Depending on the details...

0 件の賞賛
メッセージ3/10
4,220件の閲覧回数

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.



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 件の賞賛
メッセージ4/10
4,204件の閲覧回数

@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 件の賞賛
メッセージ5/10
4,198件の閲覧回数

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.



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
メッセージ6/10
4,193件の閲覧回数

@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 件の賞賛
メッセージ7/10
4,178件の閲覧回数

Maybe this will be helpful.

"If you weren't supposed to push it, it wouldn't be a button."
0 件の賞賛
メッセージ8/10
4,157件の閲覧回数

@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 件の賞賛
メッセージ9/10
4,119件の閲覧回数

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 件の賞賛
メッセージ10/10
4,106件の閲覧回数