LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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


@rolfk wrote:

@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.


How did I even forget about the various number to string methods?  Truth be told, I'm at N+1 at work right now, and my brain's a bit scrambled these days.

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 11 of 20
(1,116 Views)

@MaSta wrote:

 

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


I usually use the Format String:

rolfk_0-1675852270199.png

 

But it does a bankers rounding, while the OP wanted truncation.

 

Rolf Kalbermatter
My Blog
Message 12 of 20
(1,110 Views)

That's what I overlooked, he wanted to always round down. Then it could be like this:

MaSta_0-1675853658540.png

 

 

Message 13 of 20
(1,102 Views)

@MaSta wrote:

That's what I overlooked, he wanted to always round down. Then it could be like this:

MaSta_0-1675853658540.png


It could, but you better don't try that in a tight computing loop :-). It's as inefficient as it can get with all those number to string conversion, string subset creation and then returning back to a number. That's quite the memory manager stress tester! 🙂

Rolf Kalbermatter
My Blog
0 Kudos
Message 14 of 20
(1,099 Views)

Seems like I'm a bit lost here. If a test engineer only wants to see 2 decimal places, and floating point is an approximation but it's the value we have, what do 15 positions past what we're concerned with matter for?

~ Self-professed LabVIEW wizard ~
Helping pave the path to long-term living and thriving in space.
0 Kudos
Message 15 of 20
(1,043 Views)

Is everyone here a Bynar?

~ Self-professed LabVIEW wizard ~
Helping pave the path to long-term living and thriving in space.
0 Kudos
Message 16 of 20
(1,042 Views)

@IlluminatedG wrote:

Seems like I'm a bit lost here. If a test engineer only wants to see 2 decimal places, and floating point is an approximation but it's the value we have, what do 15 positions past what we're concerned with matter for?


There was no mention of whether or this was just for display or for calculations (e.g., compare to two decimal places) so... And if you truly believed that the OP was just asking to see two decimal places, my all the "fancy" calculations?  (And don't tell me a tale about "round down" because your calculations show round to nearest.)

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 17 of 20
(1,039 Views)

Oh I am going to chime in!

 

Computers are digital!  So, they cannot form an analog number strip.

 

IEEE 754 agreed upon a standard for floating point math functions for computing.  Those "Standards" are reasonable but not purely correct. 

 

Purely correct mathematical calculations would require HARDWARE that does not exist.

 

Well, that is not true!  If you want hardware capable of correct pure math.  Break out your "Slip-Stick" and oil it up!

 

You can be a Chamillionaire if you get 3 precise digits off of yours!  15 significant digits is enough to calculate the circumference of the Milky Way Galixy to a neutron diameter. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 18 of 20
(1,014 Views)

@JÞB wrote:

Oh I am going to chime in!

 

Computers are digital!  So, they cannot form an analog number strip.

 

IEEE 754 agreed upon a standard for floating point math functions for computing.  Those "Standards" are reasonable but not purely correct. 

 

Purely correct mathematical calculations would require HARDWARE that does not exist.

 

Well, that is not true!  If you want hardware capable of correct pure math.  Break out your "Slip-Stick" and oil it up!

 

You can be a Chamillionaire if you get 3 precise digits off of yours!  15 significant digits is enough to calculate the circumference of the Milky Way Galixy to a neutron diameter. 


I thought I read somewhere that they really only calculate pi to two decimal places for most space slingshot calculations.

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 19 of 20
(984 Views)

@billko wrote:

@JÞB wrote:

Oh I am going to chime in!

 

Computers are digital!  So, they cannot form an analog number strip.

 

IEEE 754 agreed upon a standard for floating point math functions for computing.  Those "Standards" are reasonable but not purely correct. 

 

Purely correct mathematical calculations would require HARDWARE that does not exist.

 

Well, that is not true!  If you want hardware capable of correct pure math.  Break out your "Slip-Stick" and oil it up!

 

You can be a Chamillionaire if you get 3 precise digits off of yours!  15 significant digits is enough to calculate the circumference of the Milky Way Galixy to a neutron diameter. 


I thought I read somewhere that they really only calculate pi to two decimal places for most space slingshot calculations.


I thought they rounded to 1.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 20 of 20
(964 Views)