LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I display decimal data on the front panel as fractions such as 1/32, 1/16

Of course the code would need some tweaking, because it is not perfect.

 

For example 1.99 would currently result in "1 1/1" with the default resolution and 2.0001 results in "2 1/32".

Both cases should return 2!  😞

0 Kudos
Message 11 of 30
(1,663 Views)

altenbach wrote:

Of course the code would need some tweaking, because it is not perfect.

 

For example 1.99 would currently result in "1 1/1" with the default resolution and 2.0001 results in "2 1/32".

Both cases should return 2!  😞


You think that is annoying, what do you suppose happens when you try -2.1?

Message 12 of 30
(1,657 Views)

altenbach wrote:

Of course the code would need some tweaking, because it is not perfect.


Here's a very quick and crude attempt at an improvement (LV 8.0). Please verify correct operations and modify as needed. 😉

 

Message Edited by altenbach on 12-28-2009 12:25 PM
Download All
Message 13 of 30
(1,647 Views)

Of course better would be to convert to I64 instead of I32, but then we would need to rewrite the GCD code in I64 (no big deal, simply inlining the current subVI will automatically remove the coercions :D).

 

For higher bit resolutions, we'll quickly run out of bits by using I32.

 

We also need some range checking on the inputs and generate an error if things get outside the valid ranges.

Message 14 of 30
(1,498 Views)

Dead thread, I know, but sharing another solution for future searchers.

 

I had to put this solution together when there was a forum problem and I could not download or view the solutions posted, and once I could see them it seemed to work better. At least handled negative and just-barely-off issues better than the original, and gave more layman-friendly options for fraction resolution.

I didn't benchmark this against Altenbach's solution, though, which seemed to work pretty well on a few minor test cases once I could finally see it...

 

 

Message 15 of 30
(950 Views)

This screams to be made into an XControl.

I couldn't resists.

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 16 of 30
(921 Views)

Here it is in LV2015 (and with all the pieces this time).

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 17 of 30
(906 Views)

Yet another version.  Pretty simple.

CLA
0 Kudos
Message 18 of 30
(892 Views)

Entering 2.8 yields "No fraction"

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 19 of 30
(882 Views)

Oops, looking for a fix ...

CLA
0 Kudos
Message 20 of 30
(876 Views)