F8 Floating decimal question

Rodter

Member
Join Date
Jan 2006
Location
Alabama
Posts
23
In Rslogix 500 I have an F8 data file that I need to take the decimal out of. The data is to big to move to an interger file. How do I take the decimal out of it.
Thanks
 
You may not be able to if the number is larger than 32767 which I believe you know is the limit for integers in most SLCs. If you need to use the number without the decimal but will all of its significant value, then you can try to do some math manipulations to round off the number and leave the result in the F8 file. Might be a good exercise, so let us know how you do with it.
 
What is the reason for converting the float to a whole number?

If the number is too large to convert to an integer then it must remain as a float. If it remains as a float then there is little point in converting it to a whole number.

If you want to display it as a whole nubmer then you can configure most display devices to display 0 decimal places.

There are however some not too difficult things that will either round a float or truncate a float, but we need some information about which of those it is you want to do before we proceed.

Also, which platform are you using? If its a Micrologix then we can do some tricks with L data files.
 
Hi Rodter​
Like alaric has said it would be more helpful if you gave us a bit more info on what you are trying to acheive, There is one or two ways to do it in the ladder but it all depends on what it,s required for as to which way to go program wise​
Regards​
Jonno​
 
Basically, this is not a production issue. Someone approached me with the question, so I started playing with it because it sparked some interest. I know about the 32767 cap for an interger file. I would just like to know if there is a way. All I want is the whole numbers no decimals.

Thanks again,
 
There's probably a quick and easy way to break each Float into a couple of integers--maybe one integer for 10,000's and one for 0-9999. This should take care of the 32767 limit for an integer, and should allow you to put them together to make a big non-decimal number. It shouldn't be too difficult to do it with a couple of CPT instructions.
 
I can see how that would probably work and I have even thought about that. But that would required two data files. Is there anyway to do it with just one? I am sorry if these are dumb questions.
 
I know that the number can be over 90,000. So then I guess I will just have to give up the hope in a quick one runger.

Thanks
 
rodter

Depending upon various factors and depending upon what you want to do...

You could take your number and divide it by 10, 100, 1000 etc, say 85.000/10 Div function, source A as your float number, source B as your divider, destination another float..this would give you 8.5,
then take that float value and use the multiply function, i.e..source A would be 8.5 source B multplyer and destination would be another float or interger..therefor 8.5 x 100 would give you 850 or 8.5 x 1000 would give you 8500... it,s really hard to explain unless you have a clear route as to what you want to acheive.... there are several options to do it like the others have said..

Jonno
 
Long count in SLC

May or may not help, if the count is being displayed on a SCADA system or a HMI screen there is a little bit of code that might help. The following pdf was programmed to display a count in 32bit as a LONG data type ie. 0 to 2,147,483,647 a couple of notes on the use of the logic can only count by one and not easy to work out the count value when looking at the data in the PLC registers.

Hooey
 
I know that the number can be over 90,000. So then I guess I will just have to give up the hope in a quick one runger.
Doing it with only 1 Rung is a lot more likely than doing it with only 1 16-bit memory storage loction (a word). It can easily be done using only 2 words and probably still only use 1 rung.

Many programs can read two consecutive 16-bit words as one 32 bit word.

If you still must have only 1 number in one 16-bit address, AND you can live with less accuracy, simply divide the floating-point number by 4 to get it below 32767 (131,068 maximum divided by 4 = 32767, then round it off to 0 decimal places to get rid of the fraction. The result can be displayed as one 16-bit integer number. Now the final user (device or function), (knowing that it is really X/4), only has to routinely and automatically multiply the given number by 4 before using it.
 
Just directly mainpulate the maintissa of the float.

In base 10 floaing point, a fraction is represented by a/10 + b/100 + c/1000 + d/1000 .... + z/10^n where a,b,c,d...z are numbers 0-9 and n is the number of decimal places in the fraction

Likewise In IEEE-754 32 bit floating point format (what AB PLCs use) the fractional part of the number is represented in the same way, except it is in base 2. The fractional part is a/2 + b/4 + c/8 + d/16 ....+ z/2^n where a, b, c, d,...z are binary numbers, 0 or 1, and n is the number of binary decimal places.

So, all we have to do is figure out where the fractional part of the number begins in the 32 bit float and clear all the bits in the fraction. And as luck would have it, the IEEE-754 floating point format tells us where the fraction part begins for any particular value - since it is binary we simply extract the exponent and keep that many bits of the mantissa and clear all the rest.

Here is a program that does just that.
(It helps to have an understanding of the IEEE-754 format to follow this program)

Its not the one-liner you were hoping for, but it's a nice general application that truncates any float - and it does it in 4 rungs.

EDIT: This program truncates, it does not round. If you want rounding then add 0.50 to the float before truncating it.
Thus 16.5001 would become 17.001 which truncates to 17 and 35.4 would become 35.9 which truncates to 35.
 
Last edited:

Similar Topics

Hi there, Does anyone know how to limit the # of decimal places of all floating integers displayed on the HMI? I want to display one decimal...
Replies
4
Views
7,458
RSLogix 500 FTVS-ME I have a floating integer that I only want to go 2 places to the right of the decimal point(100th) but I can't find the...
Replies
1
Views
1,660
Ladies & Gent's, I am reading a floating point number from a Seimens RWF40 controller(PV) modbus address 30000 IEEE_754 format. I want to...
Replies
11
Views
2,725
Equipment- AB HMI PV600 2711-B6C20 Control Logix 1769L32E Software- RSlogix 5000 and Panelbuilder 32 Problem- I have an analog signal back to...
Replies
0
Views
1,271
I’m using a 05 PLC which cannot handle real (floating point) numbers. The operator must enter the cut length into the C-Micro panel. (I used a...
Replies
2
Views
3,589
Back
Top Bottom