LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

round the numbers

Solved!
Go to solution

hello,

i have integer number which is variable 0.869231 and i want to round it nearest number after two decimal points such as 0.869231 should be 0.87 if it is 0.986858  the it should be 0.99.. how can i do it?

 

thank you 

0 Kudos
Message 1 of 5
(1,331 Views)

Hi new,

 


@newmemeber123 wrote:

i have integer number which is variable 0.869231 and i want to round it nearest number after two decimal points such as 0.869231 should be 0.87 if it is 0.986858  the it should be 0.99.. how can i do it?


So you have float numbers like 0.8692? And you want to round them to 2 significant digits?

 

Do you want to round them just for display purposes (see item 1) or do you want to use the rounded values later on for other calculations (see item 2)?

 

  1. Set the display format to %.2f of your numeric indicators…
  2. Multiply by 100, round to nearest integer, divide by 100. Keep in mind there will be rounding issues for the "divide by 100" operation as there are rounding issues for nearly all floting point operations…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 5
(1,320 Views)
Solution
Accepted by topic author newmemeber123

Multiply by 100, round to nearest integer, divide by 100.


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
Message 3 of 5
(1,317 Views)

First, you have a floating point number.  Integers are whole numbers 0, 1, 2, 3...

 

Multiply by 100, (or 10^nth where n is the number of places after the decimal point) round then divide by 100 (or 10^nth.)

 

Edit: I guess I type slow


"Should be" isn't "Is" -Jay
Message 4 of 5
(1,314 Views)

Just wanted to add that if you just wanted to compare two numbers (like a test result to a requirement specified to two decimal places), you can do the multiplication,as in the previous posts, for both the result and the requirement, round each to the nearest integer and then do your comparison.  This will avoid floating point issues.

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 5 of 5
(1,261 Views)