Real to int in S7-1200

tienvatco

Member
Join Date
Mar 2016
Location
Ha Noi
Posts
10
Dear all

I'm a newbie so would you please show me how to convert floating point into interger

I want to convert 12.3456 become 123456. I'm searching and see that ROUND and TRUNC but can not met my requirement

So can you help me please.

BR
 
Hi,

Under 'Basic Instructions' and then 'Conversion operations' the first operation should be 'CONVERT'.

Drag this into your program and define your floating point on the 'IN', and your integer on the 'OUT'.

You'll have to create a new tag for your integer value if you haven't already, either in a datablock or memory address.
 
Last edited:
Hi,

Under 'Basic Instructions' and then 'Conversion operations' the first operation should be 'CONVERT'.

Drag this into your program and define your floating point on the 'IN', and your integer on the 'OUT'.

You'll have to create a new tag for your integer value if you haven't already, either in a datablock or memory address.

Did you mean with 'CONVERT' I can convert 12.3456 become 123456
 
If you simply want to change 12.3456 to become 123456 then use the MATH function of MUL. Put your floating point value tag in IN1, put 10000 in IN2, and the OUT variable will be 123456.
 
I would put 10000.0 at IN2 and let the conversion happen at the OUT. Or else you end up with 120000
 
That's a good point. If you drag your REAL tag to IN1, and manually type 10000 in IN2, it'll display 10000.0 at IN2 anyway.
 
If you simply want to change 12.3456 to become 123456 then use the MATH function of MUL. Put your floating point value tag in IN1, put 10000 in IN2, and the OUT variable will be 123456.

After I read floating point 12.3456, i stored it into MD50 (Double word). I want to convert to 123456 (interger) MW60. if do not use convert. How to convert the data float to interger ?
 
You cannot store a float into a double word, but I guess that doesn't matter.

You cannot store a number that big into an integer. You are limited by your 16 bits, unsigned or signed. You will need a double integer.

multi.PNG
 
You cannot store a float into a double word, but I guess that doesn't matter.

You cannot store a number that big into an integer. You are limited by your 16 bits, unsigned or signed. You will need a double integer.

Dear boneless

You can see my program. I read value 12.3456 from Modbus RTU salve (Modbus Poll) then store it in MD50 (Double Word)

http://i.imgur.com/PDpgMDi.jpg

Now i want convert it to INT become 123456
 
Got ya.

Still, you can not store 123456 in an INT, you will need a DINT.

Just look at the picture I posted and plug in your tags there.
 
Got ya.

Still, you can not store 123456 in an INT, you will need a DINT.

Just look at the picture I posted and plug in your tags there.

Dear boneless

I see this topic and want to do the same but S71200 do not have STL. Would you please show me the way to do it

Thanks !
 
I did not post any stl. It's function block. Same thing in 1200.
 
I did not post any stl. It's function block. Same thing in 1200.

Dear Boneless

As you see my before post, When i received 12.3456 value from salve and store in PLC is Hex. Did you mean I need to convert to decimal and plus with 1000.0 as your guide. The result is Interger right ?
 
I made a boo boo in my picture. This one should be correct.

I would make a datablock and store your value there. Make sure you declare the signal as float, then it will show correctly.

multi.PNG
 
I made a boo boo in my picture. This one should be correct.

I would make a datablock and store your value there. Make sure you declare the signal as float, then it will show correctly.

Hi boneless. I very clearly with your guide but i had problem with convert hex value to real and do your math

My test is :

- Sent 12.3456 from Modbus slave to S7-1200
- The value is stored in DB and value is 16#87944145 (in Dword)
- To do your math i need to convert to real but when i use Swap then CONV, i get the number # with 12.3456

Would you help me to resolve it

Thank you !
 

Similar Topics

Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,383
I seem to be making this harder than it should be, and Its not making any sense. I simply need to move a real variable to two integer variables...
Replies
8
Views
980
Situation: Single [EQU] instruction with single [OTE] on a rung, nothing else/simple. [EQU] operand(A) is a real number data type...
Replies
16
Views
2,592
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,586
Hello I have a question about SCL if I have a real value like valor: INT I would do valor : = 1.5 Or this trhow me an error? How can I save...
Replies
6
Views
1,678
Back
Top Bottom