Posted 26 Jul 2020 Hello All, Simple question I think. What is the best way to take a DINT vale and convert it to a Real (floating point). Here is what I did. What do you think? is there a better way? Thanks very much. In this application I am obtaining a resistance value from a meter via Modbus RTU (using a ProSoft module) and wanting to display the final value on the PV 1000. Share this post Link to post Share on other sites
Posted 26 Jul 2020 Can't you just divide the DINT by 100.0 and have the Destination as a REAL ? Share this post Link to post Share on other sites
Posted 26 Jul 2020 The MOV instruction in Allen-Bradley controllers automatically converts between data types. MOV Source: MBTCP.DATA.ReadData[1] Dest: My_Resistance_Real The DIV instruction also automatically converts between DINT and REAL. I think in this case the divisor can be either 10 (DINT) or 10.0 (REAL). Neither of these changes how single-precision floating-point values are stored and represented, or rounds to a specific number of decimal places. For that, yes, a String method is sometimes required. Share this post Link to post Share on other sites
Posted 27 Jul 2020 (edited) I believe the proper solution is the DIV. Of course, that requires one to have previously MUL by the same number of digits on the other side. Edited 27 Jul 2020 by pcmccartney1 Share this post Link to post Share on other sites
Posted 27 Jul 2020 DINT to REAL is easy; just about any math instruction will handle that. REAL to DINT is an issue because you will get rounding or truncating errors. But there are only two "rules": If source A & B are not REALs, then the fractional portion of the result truncates. If source A or B are REALs, then the fractional portion of the result is rounded. But how it rounds seems to be random. For instance, if the result is -2.5, it rounds up to -2. If the result is 2.5, it rounds down to 2. Share this post Link to post Share on other sites
Posted 4 Aug 2020 ElectronGuru - I jsut read this in an old Modicon Concept Help File and it may apply here also. "Rounding when done always rounds towards 0." So 2.5 rounds to 2 and -2.5 to -2. But 2.51 rounds to 3 and -2.51 rounds to -3. Share this post Link to post Share on other sites
Posted 4 Aug 2020 35 minutes ago, BobLfoot said: ElectronGuru - I just read this in an old Modicon Concept Help File and it may apply here also. "Rounding when done always rounds towards 0." So 2.5 rounds to 2 and -2.5 to -2. But 2.51 rounds to 3 and -2.51 rounds to -3. so both 3 and -3 are further from zero than 2 or -2 so i would not consider Modicon Concept Help as a good resource to describe this. Share this post Link to post Share on other sites
Posted 5 Aug 2020 Round towards 0, round away from 0, round up, round to even...each can cause unexpected results for the x.5 case so you have to know what your platform does and act accordingly. The Logix 5000 PLCs I've used rounded to even; I don't remember what the 5s or 500s did. Or the S7-300s. Share this post Link to post Share on other sites