LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you do you round down to the nearest 100ths with labview?

For example: Control : 2.54 >>> Indicator : 2.5

                      Control: 2.57 >>>> Indicator 2.5

Is there any VI that I can use to accomplish that.

 

This is one   GRCK5000_0-1675817713697.png is good, but it only rounds down to the nearest ones. 

 

0 Kudos
Message 1 of 20
(2,069 Views)

Multiply by 100, round to nearest, divide by 100

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 2 of 20
(2,043 Views)

But since you're actually demonstrating tenths instead of hundreths: use 10 instead of 100 🙂

 

Something to keep in mind is do you really need the numeric to change or just what the indicator displays? You can set the display format to accomplish the rounding visually while keeping the full value of the numeric.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 3 of 20
(2,040 Views)

You can't really round to the nearest x decimal places with FP because the resulting rounded number will just be an approximation of an approximation.  The best you could hope for is comparing one FP number to another to the nearest x decimal places by multiplying both numbers by 10^x where x is the number of decimal places round and compare.

 

If you're not planning on using the numbers in a calculation (i.e., for display purposes only), you can similarly multiply by 10^x convert it to a string and place the decimal in the appropriate place.  Or just show x decimal places in your double indicator.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 20
(2,038 Views)

@IlluminatedG wrote:

Multiply by 100, round to nearest, divide by 100


That still gives you a FP number which will only be an approximation.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 20
(2,037 Views)

Bonus screenshot and alternate method for specifying based on the number of decimal positions desired:

precision.png

 

Edit: I'm using round nearest because I read nearest in the post title and my reptile brain skipped over "down", I'm sure it's pretty clear how to round in any direction desired based on the position.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 6 of 20
(2,023 Views)

@IlluminatedG wrote:

Bonus screenshot and alternate method for specifying based on the number of decimal positions desired:

precision.png

 

Edit: I'm using round nearest because I read nearest in the post title and my reptile brain skipped over "down", I'm sure it's pretty clear how to round in any direction desired based on the position.


I oughtta smack you for that.  Try setting the display format to 17 digits of precision.  You get 1.22999999999999998.  Like I said, it will be an approximation.  It will make it less likely that it will fail a comparison, but it doesn't eliminate it.

 

True rounding is not achievable with FP numbers.  I'll say it again.  True rounding is not achievable with FP numbers.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 20
(1,985 Views)

I will side with @Bill, floating point numbers are only an approximation.

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 8 of 20
(1,963 Views)

@santo_13 wrote:

I will side with @Bill, floating point numbers are only an approximation.


You are both right of course and at the same time the OP probably doesn't care about it! 😁

 

He wants to see his numbers in a specific way and if they are inaccurate on the 16th digit or not (that he doesn't see) he most likely couldn't care less.

 

As has been pointed out; if it is just a display question on the front panel, then adjust in the control the number of digits to display. If it is about writing strings, adjust the precision of the format specifier accordingly. And if it is indeed about calculation, then use Derrick's routine. With or without Derrick's routine, the numbers are approximations anyhow, so that routine doesn't make things substantially worse and if it is what is desired, then so be it.

 

For this specific case some code is needed since he seems to want truncation. The display precision does perform an arithmetic rounding (more precisely the Banker's rounding where 0.5 is rounded to the next even number). This is also the default rounding mode for IEEE 754 floating point numbers.

Rolf Kalbermatter
My Blog
Message 9 of 20
(1,926 Views)

My approach is simpler. A double indicator can be setup to have 2 decimal places and will automatically round the displayed value.

MaSta_0-1675847825596.png

How man places to show can also be programmed via a property node. I a test it didn't work for me, seems to be a bug in LV 2015.

Doing it manually in the indicator properties dialog worked.

MaSta_1-1675848051263.png

 

 

 

0 Kudos
Message 10 of 20
(1,918 Views)