Simple conversion from DINT to REAL fail

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

Anyone who understands this issue...
I try to convert 12345678 DINT to REAL
And I get

12345680,0 in REAL ????

DTR.png

Thanks,
Combo
 
Deleted my misleading post. Floating point mantissa is 23 bits so 12345678 will not fit hence loss of precision.
 
32-bit floating point numbers give you seven significant digits. This is the case for all devices, not just the PLC. So a DINT 12345678 will be rendered as 1.234568 x 10^7 in 32-bit REAL. Note that the 8-digit 1.2345678 rounds to 1.234568.
 
Last edited:
Deleted my misleading post. Floating point mantissa is 23 bits so 12345678 will not fit hence loss of precision.




It's actually 24 bits of total* mantissa cf. here - don't forget the "invisible" MSbit that is a 1: 24 bits of mantissa; 8 bits of exponent (excess 127); 1 bit of sign; talk about 33 punds of baloney in a 32-pound bag!



* not stored


So a 32-bit float should not lose precision until it goes above 2**24 = 16,777,216, and 12,345,678 is less than that.


The problem is not in the bits representing the number.


In the OP example, 12345678 is still in the float, and that can be verified by copying it back to another DINT (is anyone interested in a wager?;)); it is the display of the number that is limited to 6 decimal digits after the decimal point; the [78] - 6th and 7th post-decimal-point digits - at the end that are rounded to [80] and the trailing zero dropped; so the [7] didn't go anywhere, it's the [8] that is lost - in display only.
 
Last edited:
Hi,

Anyone who understands this issue...
I try to convert 12345678 DINT to REAL
And I get

12345680,0 in REAL ????




Well, actually it looks to me like you got 1.234568E+007, which is not identical to 12345680,0.


OT: do we call that thing between the zeros a "decimal comma?"
 
Thanks for the link showing the 24 bit total. I'll post a screen shot here as links can sometimes get lost:

float3.jpg
 
OT: do we call that thing between the zeros a "decimal comma?"
Commas as decimal places are quite common in Europe. Or more to the point (excuse the pun), the "," symbol is the decimal separator, and in some cases, the "." symbol is used to separate the thousands in a long number, the way the USA does with the "," symbol.

e.g. in some locales:
1,234 = a number slightly larger than 1
1.234 = one thousand, two hundred and thirty four
Whereas in the US, it would be the other way around.

This is one of many reasons managing different languages and system locales is a challenge for SCADA software (and computing in general)
 
Interestingly, their very own conversion block gets it right:


Noice.


These last two posts, especially L\ D's, put the nail in the coffin for this thread: the software (TIA Portal?) chooses to display at most 1+6 significant digits when it switches to exponent format. That's neither here nor there, but in the bits behind the display everything operates as it should.
 

Similar Topics

this will be a simple answer for someone who is used to allen bradley im using a Micro830 with a 2711-T6T panelview, and programming with CCW in...
Replies
0
Views
2,813
Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
159
Hi all, Writng a FB in ST on Beckhoff TC for a pulser which turns on and off on a cycle, is paused by turning bControlInput to FALSE, but resumes...
Replies
6
Views
247
I'm trying to build my Classic Step 7 programming skills this weekend. I get stuck on little things that are not covered in YouTube tutorials. I'm...
Replies
7
Views
316
I have a program that does a 7 second "scan" sensor calibration routine whenever a setting (setting is called assistance level or "AL" and ranges...
Replies
3
Views
212
Back
Top Bottom