Is there a simple way to do multiplication by a fraction in Labview? If I want to multiply by like 9/5s I could obviously put 1.8 and multiply that or do a separate operation to first divide 9 by 5 and then multiply the result from that, but the first loses clarity and the second is cumbersome. I'd like to be able to just input like '9/5' and have Labview work with that.
Asked
Active
Viewed 105 times
0
-
If the data type is a float, just multiply by 9/5, i.e. 1.8, as shown in NMech's answer ... If it is an integer, you can avoid the conversion by doing classic integer math: multiply by 9 first, then divide by 5. However do check for overflow. As for the rounding error: You have 2 options for improved rounding: option 1: if the product is positive, add half the dividend to the divisor (if the product would be negative, subtract instead of adding). Option 2: keep the remainder from each division, and add it into the dividend in the next operation. Option 2 limits accumulated error to
– Pete W Aug 18 '21 at 16:17 -
also note, for signed integer division, there are 4 overflow cases, if I remember right, so check them all – Pete W Aug 18 '21 at 16:20
-
If you're talking about how to let the user input an expression like "9/5", you could parse it with a Regex ... count the number of "/", and if exactly 1, split the string on "/", first part is dividend, second part is divisor, etc etc – Pete W Aug 18 '21 at 16:22
1 Answers
2
This is very much depended on version but you can try:
In your case it would look like

- mathscript (if you have the license)
However another option would be to:
- create a Subvi with a meaningful icon. (this is probably the more labview way, although its a pain it the a** to keep all the files in order, if you go down that road.
That has a very basic block diagram
However IMHO this is overkill.
To be honest, if you plan to work with Labview a lot I suggest you buy the bullet and start using the palettes.
NMech
- 23,917
- 2
- 30
- 72


