# LabVIEW

cancel
Showing results 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    is good, but it only rounds down to the nearest ones.

Message 1 of 20
(824 Views)

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

Multiply by 100, round to nearest, divide by 100

~ The wizard formerly known as DerrickB ~
Message 2 of 20
(798 Views)

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

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 ~
Message 3 of 20
(795 Views)

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

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

(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 4 of 20
(793 Views)

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

@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

(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 5 of 20
(792 Views)

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

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

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 ~
Message 6 of 20
(778 Views)

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

@IlluminatedG wrote:

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

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

(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
(740 Views)

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

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

Santhosh
Soliton Technologies

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

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

@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
(681 Views)

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

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

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.

Message 10 of 20
(673 Views)