Industry Online Support
Technical Forum
10/17/2012 11:42 AM | |
Joined: 1/3/2006 Last visit: 2/19/2024 Posts: 726 Rating: (71) |
[img]/tf/WW/en/postattachments/download?attachmentId=31916&onlyInternet=False[/img] |
10/17/2012 11:47 AM | |
Posts: 113 Rating: (0) |
round fuction i will not get the decimal value ,i want the decimal value also |
10/17/2012 1:24 PM | |
Joined: 9/27/2006 Last visit: 11/11/2024 Posts: 12293 Rating: (2691) |
Hello pada; The decimal value is only available in REAL (IEEE floating-point format). This is basic number format definition, and has nothing to do with the type of PLC or computer being used. See Wikipedia for a brief introduction: http://en.wikipedia.org/wiki/IEEE_floating-point Rounding (or truncking) will by definition remove the decimal value, as integers (16-bit INTsor 32-bit DINTs)do not have decimal points. So if you have a value of 32.1, transforming into an integer will, by definition, give ou 32. When we want to use a 16-bit integer to transport a floating-point value (using Modbus standard registers, for example) we are in the habit of mutiplying the floating-point value so the value after the decimal point is visible, then transforming the new value into an integer. At reception we then transform the value back in REAL format. Let's look at the value 32.1 once more, which I need to send as a 16-bit integer. I start by multiplying it by 10.0, so I get 321.0 (a REAL floating-point value). I round this to an integer 321 (DINT in S7, converted to an INT on a subsequent operation). I send the integer value 321 to my comm. partner as a 16-bit integer. He knows that this value must be converted to floating point 321.0 and divided by 10.0 to obtain the original value (REAL 32.1). He knows because I told him beforehand that he should expect this. Hope this helps, Daniel Chartier |
Last edited by: dchartier at: 10/17/2012 5:58 PM |
|
This contribution was helpful to2 thankful Users |
Follow us on