Separating Integer and Floating parts

Shepardt

Member
Join Date
Oct 2018
Location
Brasil
Posts
9
Hello everyone !
Is there a way to get a variable, like a Word Memory (MW) and separate the integer part and the float part and save them in different memories using the structured language, more specifically the PL7 ?
 
Each language will have their own ways depending on the instruction set.

TRUNC will give you the integer part of the floating point value.
If your variable is in MW0,
MW2 = TRUNC(MW0)
MW0 = MW0 - MW2
Then multiply by whatever decimal places you want to know (imagine two).
MW6 = MW0 * 100

Then do the same thing
MW4 = TRUNC(MW6)
MW2 will have the integer part, MW4 will have the decimal places part.

Mind that I don't know how the addressing works, I'm just writing how it can be achieved and you can also change the order of some instructions to get the same thing.
 
Each language will have their own ways depending on the instruction set.

TRUNC will give you the integer part of the floating point value.
If your variable is in MW0,
MW2 = TRUNC(MW0)
MW0 = MW0 - MW2
Then multiply by whatever decimal places you want to know (imagine two).
MW6 = MW0 * 100

Then do the same thing
MW4 = TRUNC(MW6)
MW2 will have the integer part, MW4 will have the decimal places part.

Mind that I don't know how the addressing works, I'm just writing how it can be achieved and you can also change the order of some instructions to get the same thing.
Thank you cardosocea for your answer. That will be very usefull for me.
I will keep that in mind.
 
Yes and no.
%MW is not address for real/floating it is for integer.
Simple solution would be to convert it in integer and result (integer) would be without float part, but if it is %MW than i would presume that value just value x 10 or 100 or 1000.
 
Yes and no.
%MW is not address for real/floating it is for integer.
Simple solution would be to convert it in integer and result (integer) would be without float part, but if it is %MW than i would presume that value just value x 10 or 100 or 1000.
Hum...I see...
So i can't store inside the %MW nothing else than integers ?
And what if i need to use the decimal part too ?
 
Hum...I see...
So i can't store inside the %MW nothing else than integers ?
And what if i need to use the decimal part too ?


You need to move your decimal point on PLC (multiple by 10, 100, 1000) and divide back on scada or HMI side decimal point to correct place.


Or you can use %MF memory area (one %MF takes two %MW addresses). Floating numbers have also disadvantages (them round numbers)
 

Similar Topics

I am in process of implementing a new network to separate the manufacturing floor from the Enterprise network. See attached basic diagram. I have...
Replies
0
Views
921
i have a customer who is pushing back on something i have not encountered before. the cabinet is a local control panel consisting of PL, PB, HMI...
Replies
14
Views
4,502
Hi, all. I seemed to have hit a wall on my decimal to fraction forum. Therefore, anyone know how to separate a number like 17.33333 into 17 and...
Replies
9
Views
4,024
I have heard a lot about separating the high voltage (>50V) from the lower control voltage in an electrical control panel, but have never run...
Replies
14
Views
7,174
Has anyone read a long 2D data matrix (200+ characters) and separated out the data in to different fields (~twenty)? I plan on adding a comma...
Replies
0
Views
1,302
Back
Top Bottom