SNAP PAC Learning

Started by kdowney@opto22.com at 06-29-2007 2:37 PM. Topic has 0 replies.

Print Search
Sort Posts:    
   06-29-2007, 2:37 PM
kdowney@opto22.com is not online. Last active: 6/30/2007 3:46:35 AM kdowney@opto22.com

Top 500 Posts
Joined on 06-30-2007
Posts 1
What is the difference between a float variable and an interger variable?

An integer variable is a whole number, i.e. 400, 0, or -3.  A float variable is a number with a decimal, i.e. 3.14 or 98.6.  Digital inputs and outputs are usually stored in integers while analog inputs and outputs are usually stored in float variables.  You can store a decimal in an integer variable just know that the number will be rounded to the closest integer.  Likewise, you can store an interger in a float variable and the number will have zero after the decimal point.    

However, if you have a large integer number (such as 123,456,789) and move it to a float variable, the number will be stored as 1.234568e+008.  It is stored this way because of the limitations of storing a float value in a 32-bit memory location.  When you move this float variable back to an integer variable, the number may be incorrect because of the rounding that happened during the move from the original integer to the float.  For example, when I move 1.234568e+008 to an integer variable, the integer value is 123,456,792. 


   Report 
OptoForums » Product Forum » SNAP PAC Learni... » What is the difference between a float variable and an interger variable?

Powered by Community Server, by Telligent Systems