Parse a Floating Point Number

Chuck Woodbury

Lifetime Supporting Member
Join Date
Apr 2005
Location
Valley Springs, California
Posts
78
I am tracking production and accumulating it into a floating point number. In order to display that on an AB InView Message Display I have to parse the floating point into 6 or 7 individual digits and move each digit to an integer file. Does anyone know an easy way to accomplish this short of doing all the math and audits it will take to break it down.
 
I you get specific with the significance of the digits it would help. An alternative would be to do the accumulation process in the format for the message display in parallel with the floating point number accumulation - this would save you having to convert later.
 
Here's how I do that...

What degree of accuracy do you need to display?

If it's 2 decimal places, then multiply your float by 100 at the beginning and start with that result when you break it down into integer sized pieces. Then when you are displaying the result, you have to make the decimal point appear correctly, (...divide it by 100 or scale it...depends on the display software...)

You should be able to do this with just two integers. Use one for the least significant half, and the other for the most significant half, display them sided by side on the display, and enable leading zeros for the least significant half (or both for best appearance when the value rolls over 9999)

Lets say: BDFT = 123456.78 (floating point address)

and BDFT_x, MS_bdft, and LS_bdft are all integers

BDFT_x = BDFT * 100 = 12345678

MS_bdft = BDFT_x / 1000 = 12345
LS_bdft = BDFT - (MS_bdft * 1000) = 678

Then display
MS_bdft;LSBDFT
or
12345;678

and manipulate the decimal place as required by the HMI software to get:
123456.78

This is only good up to 8 digits, and a round up may occur in the first divide, depending on your processor. In that case you may have to write logic to detect that and subtract it back out...If you need a different level of precision or more digits, the logic can be modified to achieve that, but hopefully this will get ya started...

Paul
 
Just tried something else and I think it solved my problem.
Divide F50:66 (Total Board Footage) by 100 store at N137:30.
NXB CPT expression F50:66 - (N137:30*100) store at N137:31
Or
SOR BST CPT N137:30 F50:66|100 NXB CPT N137:31 F50:66-(N137:30*100)BND EOR
That got my numbers small enough to send to the InView and the accuracy is within 10 BF.
Thanks everyone for your assistance.
 
Masked Move

Chuck,

Have you tried a masked move, MVM. You might have to scale it up or break it into two integers to do it this way.

$0.02

Thomas
 
Paul,
I get the same results as with what I tried. I had to use 10000 because 1000 drives the value negative when above the rounding point.
The first compute rounds up when above the 5.
So 345867 becomes 3459.
The second one I can adjust for with a LES in the branch then do this math. BF_LS x .01 x -1 + 50 and it gets the last two numbers to go positive and pretty close as well as gets rid of the decimal point.
Maybe I will just use the first divide and add two 0's. We will be within 100' of actual.
 
This seems to work. It is a PLC5 - RSLogix5
SOR XIC B133/15 BST CPT N137:30 F50:66 | 100.0 NXB MUL N137:30 100.0 F138:0 NXB GRT F138:0 F50:66 SUB N137:30 1 N137:30 NXB CPT N137:31 F50:66 - (N137:30 * 100.0) NXB LES N137:31 0 CPT N137:31 (F50:66 - (N137:30 * 100.0)) + 100.0 BND EOR
Chuck
 
Chuck Woodbury said:
...So 345867 becomes 3459....

So your processor rounds up...now you have to add another chunk of logic to handle that...I've done that before in a SLC503, but I don't remember exactly what I used. I think I did something like this:

Float_x = 345867
Float_y = Floatx/100 (3458.67)
Int_y = Floatx/100 (3459)
Float_d = Float_y-Int_y (-0.33)
If Float_d < 0 then Int_y = Int_y-1

Now it is getting kinda hairy looking...tell us which processor you are using and there may be a much cleaner way to do the same thing without all the extra fuzz! I leave work at 1:30, but I bet Alaric will have something good to add...

PC
 
Last edited:
I am no Alaric (or Paul for that matter), but have you looked into moving your float to a int, then using AND (Bitwise AND) then DIV that...

Just a thought
 
Just another $.02. In previous app. on a 5 in order to maintain the rounding integrity subtracting .49 seemed to do the trick this was for converting drop time hours into days.

CPT N70:84 (N70:82 | 24.0) - 0.499
 

Similar Topics

Hi All, It's a long shot, but is there a way that a routine or AOI is written to scan all routines (routine names can be fed as inputs? if...
Replies
4
Views
606
Is there a way to export/import parse-able files of the PLC program of a Mitsubishi Electric (MELCO) iQ-R PLC? I am working with iQ-R PLC...
Replies
5
Views
1,835
Using Logix Designer, I have a UDT with multiple members Time_Stamp..REAL Min........ REAL Max........ REAL Avg........ REAL...
Replies
12
Views
3,325
Basic info: Wonderware System Platform 2014 Archestra Workflow External system, Alarm generated Text file With fixed delimiter I need some advice...
Replies
0
Views
3,043
hello all: I use a opc client to read data from AB controllogix through 1756-enbt.when i read a variable with the tag name 'a',the packet is...
Replies
0
Views
2,841
Back
Top Bottom