LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to round with decimals in labview?

Hello,

I would like to know if there is any function wich returns a number x
rounded to n decimal places (like ROUND(x,n) in Mathcad).

I know the Labview's ROUND function, but it returns only an integer and I
can't choose the decimal places.

For example: if x = 2.6873, I want n = 2 decimal places so it should
return 2.69. Labview returns 3 without decimals.

Thanks for any answer given.

Raul Fernandez (acicate@latinmail.com)
0 Kudos
Message 1 of 41
(38,260 Views)
Hallo, cad05,

Du meintest am 31.05.00 zum Thema How to round with decimals in labview?:

> For example: if x = 2.6873, I want n = 2 decimal places so it
> should return 2.69. Labview returns 3 without decimals.

round(100*x)/100

Viele Gruesse!
Helmut
0 Kudos
Message 2 of 41
(38,252 Views)
Hello,

> I would like to know if there is any function wich returns a number x
> rounded to n decimal places (like ROUND(x,n) in Mathcad).
>
I surmise you want to choose the appearance of the string representing
your numbers; the binary notation in memory corresponds to a well
defined format like int, float,extended etc;
If you just want to chose the format of the string appearing in a
numeric indicator, you can do this via "Format and precision" (popup).
If it is for writing formatted numbers to a file, most of the
number-to-string or number-to-spreadsheet vi's give you the possibility
to specify a 'C' like format.
It would be better to know what exactly you need in order to give a
useful answer.
--
Pierre Meyer                        
Laboratoire de Physique des
Solides     
Bt. 510, Universite de Paris Sud         
F 91405 ORSAY, FRANCE               
T : (33)-(0)1 69 15 60 62
Fx : (33)-(0)1 69 15 60 86
e-mail : meyer@lps.u-psud.fr
homepage : http://www.lps.u-psud.fr/
0 Kudos
Message 3 of 41
(38,252 Views)
cad05 wrote in message news:MPG.139ef94f2d75d643989681@news.teleline.es...
> Hello,
>
> I would like to know if there is any function wich returns a number x
> rounded to n decimal places (like ROUND(x,n) in Mathcad).
>
> I know the Labview's ROUND function, but it returns only an integer and I
> can't choose the decimal places.
>
> For example: if x = 2.6873, I want n = 2 decimal places so it should
> return 2.69. Labview returns 3 without decimals.

If you wish to "round" it for a display.. you can change the precision of that display. Right click on the display, select "Format
and precision" and select hte number of decimals you wish to see.

If you wish to change the actual data.. you could always first multiple the number by 10^n, ro
und, and then divide by 10*n

For example, ( Round to Nearest [ 2.67873 * (10^2) ] ) / ( 10^2 ) should return 2.68

Note: even if you have an integer of "2".. if your format and precision is set to 4 places, it'll still show as 2.0000 on the
display.

HTH
--
Keith M Ryan
Applications Engineer
JL AUDIO, Inc
Get shocked! http://www.jlaudio.com/
Message 4 of 41
(38,252 Views)
cad05 wrote:
>Hello, >>I would like to know if there is any function wich returns a number
x >rounded to n decimal places (like ROUND(x,n) in Mathcad).>>I know the
Labview's ROUND function, but it returns only an integer and I >can't choose
the decimal places.>>For example: if x = 2.6873, I want n = 2 decimal places
so it should >return 2.69. Labview returns 3 without decimals.>>Thanks for
any answer given.>>Raul Fernandez (acicate@latinmail.com)>

The best way to round numeric values to a specific precision is to avoid
floating-point like the plague. Convert the value to a string, format the
string, and then convert back to numeric. You should also add a very small
positive offset value to your initial numeric before converting to string
to avo
id the dreaded even/odd rounding errors of PCs. I've sent you a VI
to examine.
0 Kudos
Message 5 of 41
(38,248 Views)
On 10 Jun 2000 22:27:24 -0500, Tariah wrote:
>
>cad05 wrote:
>>Hello, >>I would like to know if there is any function wich returns a number
>x >rounded to n decimal places (like ROUND(x,n) in Mathcad).>>I know the
>Labview's ROUND function, but it returns only an integer and I >can't choose
>the decimal places.>>For example: if x = 2.6873, I want n = 2 decimal places
>so it should >return 2.69. Labview returns 3 without decimals.>>Thanks for
>any answer given.>>Raul Fernandez (acicate@latinmail.com)>
>
[...]

My solution would be to multiply by 10^N, round and then
divide by 10^N. I will send you a vi that does exactly this.
Further it even sets the precession of the disply to N.

Cheers, Tobias

--
**********
************************************************************
Tobias Vancura Email: tvancura@NxOxSxPxAxM.solid.phys.ethz.ch
Message 6 of 41
(38,248 Views)
I'm inclined to agree with avoiding floating-point numbers. Even by manually entering a floating-point value it isn't possible to alleviate the residual decimals that take a ride along with the desired data. In my opinion this is a Labview bug that needs resolved by National instruments.

I've tried the multiply by 10^x converting to integer then adding and dividing by 10^x and as soon as the divide takes place the dreaded floating-point decimals start rearing their ugly heads again, playing havoc with my accuracy.

I'm thinking the best approach might be to write the function using C-code then call it from Labview. This kinda negates the reason for using labview though??
Message 7 of 41
(38,248 Views)
Your residual decimals is not a problem with LabVIEW. It is inherent with computers and binary representation of decimals. I remember being taught this in some 101 level classes many years ago. You can do it C, Visual Basic, Delphi, Fortran, or Cobol and still have the same issues.
0 Kudos
Message 8 of 41
(38,248 Views)
Try this too.


ian.f
ian@ianfung.net
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 9 of 41
(37,993 Views)
"Revilo" wrote in message
news:506500000005000000E0B70000-1031838699000@exchange.ni.com...
> I'm inclined to agree with avoiding floating-point numbers. Even by
> manually entering a floating-point value it isn't possible to
> alleviate the residual decimals that take a ride along with the
> desired data. In my opinion this is a Labview bug that needs resolved
> by National instruments.
>
> I've tried the multiply by 10^x converting to integer then adding and
> dividing by 10^x and as soon as the divide takes place the dreaded
> floating-point decimals start rearing their ugly heads again, playing
> havoc with my accuracy.
>
> I'm thinking the best approach might be to write the function using
> C-code then call it from Labview. Th
is kinda negates the reason for
> using labview though??

You might have some part of your code that has a representation of single.
A number that is a single will only give you 6-7 places of accuracy and a
double will get 15-16 places. Check your controls, indicators, and
constants (check all nodes actually) for representation. A quick way to
check is to check the wires coming off of them using the wiring tool and
context help. good luck.
0 Kudos
Message 10 of 41
(38,248 Views)