01-05-2015 09:55 AM
Hello guys,
For example, If i have:
3.56121 I want 3.6
3.55000 I want 3.5
I want get float number and get only round up if the number is > than 5 and maintain only one decimal digit.
Regards.
01-05-2015 09:59 AM - edited 01-05-2015 10:10 AM
EDIT: did not test...not what you wanted here.
here ya go....
01-05-2015 10:11 AM - edited 01-05-2015 10:11 AM
Are you sure you don't want to round up with 5? That is how "conventional" rounding it done.
Anyways, here's what I quickly came up with. I'm sure there's better ways out there.
01-05-2015 10:26 AM - edited 01-05-2015 10:36 AM
There are several rounding principles. LabVIEW uses for its Round() node what is called unbiased rounding according to IEEE floating point standard. This means that LabVIEW will round 0.5 to the nearest even number. If 0.5 would always be rounded up, then given a random number of samples the average of all roundings would tend to be a little bit higher than the average of the random numbers, whereas with unbiased rounding both averages tend to be the same given a high enough number of samples.
This might not be of concern for some applications but it is definitely an issue if you use the resulting numbers for anything that involves statistical analysis (or financial transactions ).
01-05-2015 11:48 AM
You also need to specify what happens for negative numbers--do they round toward negative infinity (ie, Round Half Down), or toward positive infinity (ie, Round Half Toward Zero)? The former introduces an overall negative bias but preserves the average magnitude while the latter is unbiased but reduces the average magnitude.
01-05-2015 03:11 PM - edited 01-05-2015 03:20 PM
Thanks guys for replies!.
The examples no works. Only if I have only 2 decimal. IF you got 4 or 5 no works.
Yes, only for positive values. I dont work with negative. But I got the idea.
Thanks for your time guys.
Regards.
01-05-2015 03:32 PM - edited 01-05-2015 03:33 PM
You somehow need to define what the last digit is. You may think that if you display a number in a control and it shows 1.2345 that is the exact value in memory but for almost all real world floating point values there is not an exact number in a computer without using up indefinit amounts of memory. Type in above number in a digital control then go into the properties and make it show 16 digits and you will see a number like 1.23449999999999993. This is the closest number to 1.2345 a computer can represent when using the standard IEEE floating point numbers.
So if you want some specific rounding you have to define on which digit it should be rounded. There is no intelligence in the world that could automagically guess what your definition of the right digit to round would be. If you know which digit you want to round you can employ an according multiplication to shift that digit to the first digit after the decimal point, do the rounding and then divide by the same value to scale the value back to its original. And last but not least you have to make sure that any control that displays this value is set to only display the desired amount of digits or when you convert the number to a string make sure to specify the actual amount of digits to format into the string.
01-05-2015 04:10 PM
Fonsi wrote:
The examples no works. Only if I have only 2 decimal. IF you got 4 or 5 no works.
It is just a matter of changing your multiplier before doing the round and divisor after.
01-05-2015 04:17 PM
Which example doesn't work? Why do you think it would be different for 4 or 5 decimal places instead of 2?
Post your current VI, and a list of examples that you have. What your inputs would be and what you expect the outputs would be.
It seems like English is probably not your native language, so perhaps there is something missing in the communication on what you are trying to do.
01-06-2015 02:46 AM - edited 01-06-2015 02:47 AM
Hello,
Check the file attached. You can see the both examples didnt work well. Like crossrulz said, I need to have 2 decimal for work.
In the capture I added with the data fixed to have 2 decimal, and now it works. It take more code what I expected.
BTW, any better way to fix the float number to 2 decimal?.
Thanks and sorry, yes It is not my native language.