LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert decimal into integer

Hello i think that's a simple question. I've to convert a decimal number (such as 0,1 ) into an integer number such as 0.

What should i do? i tried with functions >> numeric >> conversions >> to long integers but i saw  it has only integers as input. 

0 Kudos
Message 1 of 5
(10,560 Views)

Not 100 percent sure what you wanted, so I've provided 3 alternatives.

 

  1. Mathematically rounds the number to the nearest whole value (integer)
  2. Divides the number by 1 (can be any constant, but for your case, 1 is used) and returns the quotient and remainder.  The quotient is the number as if it was rounded down to the nearest whole value (integer)
  3. Blindly converts your single precision (I assume this is your data type) to a long integer.  This will also get rid of the decimal place.

I hope this helps.

 

  1.  
 
P.S.  Examples 1 & 2 use DBL precision values - these are interchangeable with SGL precision values, assuming you only need 1dp precision.
Message Edited by James Mamakos on 05-11-2009 10:53 AM


Never say "Oops." Always say "Ah, interesting!"

Message 2 of 5
(10,551 Views)

One addition to method 1 James posted:

Round towards nearest integer has one "exception" common to most programming languages:

If the value of the input is midway between two integers (for example, 1.5 or 2.5), the function returns the nearest even integer (2).

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 5
(10,531 Views)

Norbert B wrote:

One addition to method 1 James posted:

Round towards nearest integer has one "exception" common to most programming languages:

If the value of the input is midway between two integers (for example, 1.5 or 2.5), the function returns the nearest even integer (2).


 

...Wow - you serious about this?  I've absolutely never heard of that before - I'll admit I'm not that experienced with programming languages though.  Why does it do this - isn't this functionality rather illogical?  It certainly strikes me as odd, but then i don't know exactly how the computer works it out.

 

Could someone shed some light on this for me please.



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 4 of 5
(10,490 Views)

James Mamakos wrote:

...Wow - you serious about this?  I've absolutely never heard of that before - I'll admit I'm not that experienced with programming languages though.  Why does it do this - isn't this functionality rather illogical?  It certainly strikes me as odd, but then i don't know exactly how the computer works it out.

 

Could someone shed some light on this for me please.


Here is an explanation why.

 

Chris M

0 Kudos
Message 5 of 5
(10,484 Views)