Proper Use of FLOAT
TurnipTruck
Posts: 1,485
Greetings,
I am working on a project in which I am monitoring analog to digital convertors. The convertor resolution is 12-bit (4,095 possible values).
In the process of calculation, I need to arrive at a decimal value less than one. I always thought that this would be the place for a FLOAT variable.
DEFINE_VARIABLE
FLOAT fVOLTS
....EVENT....
fVOLTS=(((cTRANS_MESSAGE[9]*256)+(cTRANS_MESSAGE[10]))/4095)
Removing the /4095 will return a 12-bit range integer value for fVOLTS, but trying to divide that value by 4095 gives zero. I am observing the zero value in debug as well as with an FTOA sent to a touchpanel.
Any help appreciated. Thank you.
I am working on a project in which I am monitoring analog to digital convertors. The convertor resolution is 12-bit (4,095 possible values).
In the process of calculation, I need to arrive at a decimal value less than one. I always thought that this would be the place for a FLOAT variable.
DEFINE_VARIABLE
FLOAT fVOLTS
....EVENT....
fVOLTS=(((cTRANS_MESSAGE[9]*256)+(cTRANS_MESSAGE[10]))/4095)
Removing the /4095 will return a 12-bit range integer value for fVOLTS, but trying to divide that value by 4095 gives zero. I am observing the zero value in debug as well as with an FTOA sent to a touchpanel.
Any help appreciated. Thank you.
0
Comments
--D
Is there an easy way to truncate a FLOAT value down to a pre-determined number of decimal places?
I need not display beyond .xx for my purposes.
Thanks!
FORMAT('%-5.2f',123.234) '123.23'
Check the Netlinx Keyword Help: Index - FORMAT