Converting real data type from Siemens PLC (S7-1200) to be displayed in Visual C# Windows Form

Viewed 5379

I am trying to read a real value from a Siemens PLC (S7-1200) and display it in Windows Form. I am using the S7.NET library to communicate with the PLC and a TIA Portal V15 to program/Monitor the PLC.

I am able to read the particular data block (DB3.DBD0) in the Windows Form from the PLC, it does return a value, but the value is displayed in some other format. For example, if I modify the value in DB3.DBD0 to "2.22", it gives me "1.074665+09". I would like it to return the same value as in the TIA Portal which is "2.22".

Below is the code I am using to convert the values.

object real0 = Convert.ToSingle(plc.Read("DB3.DBD0"));
label43.Text = real0.ToString();

If my question is not clear, please let me know, I can try to explain in more detail.

Thank you in advance!

2 Answers
Related