LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Numeric fraction input, 1 3/4, 1 11/16, 7/8 etc..

Solved!
Go to solution

Is there a built-in way to convert a integer-fraction notation (enterd by a user on FP) to it's approximate double precision value?

 

For instance, if the user types "1", then the double precision value is simply 1, if they type "1 11/16" then the value would be interpreted as 1.6875. By default, labview ignores non-numeric data entered into a numeric control so typing "1 11/16" does nothing.

 

I know I could brute force this by using a string control, testing for a space after the first integer and parsing out the numbers before and after a "/" or "\" ...and so on, but I was wondering if there is an easier way, more elegant way to handle this.

Philip
CLD
0 Kudos
Message 1 of 11
(3,465 Views)

Well a double is a real, while "1 16/17" is a rational number. So any double can't be expressed the way you want? And is it really that undignified to make a subVI that does the job?

Best regards,

Jarle Ekanger, MSc, PhD, CLD
Flow Design Bureau AS

- "The resistance of wires in LabVIEW is not dependent on their length."
0 Kudos
Message 2 of 11
(3,445 Views)

Hi Philip,

 

to make it more "easier" you could put that functionality into a XControl.

Or use SearchAndReplaceString to replace spaces by "+" and call one of those formula functions to evaluate the expression...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 11
(3,437 Views)

I would make a cluster with whole numers, numerators and denometer (probably an enum) and handle a value change on teh cluster and turn it into a double.  No easy button that I know of.  I think the cluster of 2 ints and an enum would have the least bounds checking. 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 4 of 11
(3,428 Views)

... use an ActiveX interface to EXCEL? EXCEL accepts input like =1 + 11/16 and computes it properly. It's a matter of taste if you want to call such an approach more elegant.

 

Cheers

Edgar

0 Kudos
Message 5 of 11
(3,400 Views)
Solution
Accepted by topic author p-rose

Simple  minute implementation.

Very crude.

 

Could add tabing, and events and bounds checking.  Should make a typdef and add functions for this typdef.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 11
(3,388 Views)

I like that this is safe, i.e. can't divide by 0 and relatively light weight. I can make it look and feel a little prettier, thanks for idea.

Philip
CLD
0 Kudos
Message 7 of 11
(3,380 Views)

Hi Philip,

 

less safe, quite simple:

check.png

You can

- use ErrorOut of ScanFromString to check for invalid input

- put this into an Event structure after setting the string to "update while typing"

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(3,357 Views)

fractional input might be a nice idea to add to the forum if not already there.

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 9 of 11
(3,341 Views)

Yes, i'm sure it's a fairly common "want to have" but I guess most people just work around it by either memorizing the equivalent decimal input or using an intermediate tool (calculator or printed look up table). I couldn't believe no results came up when I searched before making this post.

Philip
CLD
0 Kudos
Message 10 of 11
(3,317 Views)