Originally created by: phenixrb
Hello everyone ,
I need help with rounding, in "UINT_TO_LREAL" conversions. how is it possible to recover the unrounded values as in the upper table?
and why, all are not rounded, for example the value "1.22"?
at best, I would like to be able to use values to 2 decimal after the decimal point, like the value "1.22".
thank you.
Tools > Options > Text Editor > Monitoring > Number of displayed digits https://help.codesys.com/webapp/_cds_dl ... n=3.5.15.0 m
Originally created by: D. Kugler
you can use the TO_DINT funktion to throw all decimals away, so before 100.0 afterwords /100.0: AIN01R:= TO_LREAL(TO_DINT(AIN01100.0)/100.0);
Actually there is a type inconsistency in your formula : LREAL:=UINT_TO_LREAL(UINT (I beg))/INT*REAL
Then, REAL/LREAL are stored and interpreted (IEEE float format https://en.wikipedia.org/wiki/Double-precision_floating-point_format). That's why your values can't be exactly the same.
If you need to get back your precise value, then I would suggest working with DINT and using scaling (*100) for you math.
The type you need is called DECIMAL, but as far as I know, isn't supported in automation systems.
HI,I-Campbell
thanks for your answer, that's what I was looking for.
Log in to post a comment.
Originally created by: phenixrb
Hello everyone ,
I need help with rounding, in "UINT_TO_LREAL" conversions.
how is it possible to recover the unrounded values as in the upper table?
and why, all are not rounded, for example the value "1.22"?
at best, I would like to be able to use values to 2 decimal after the decimal point, like the value "1.22".
thank you.
Tools > Options > Text Editor > Monitoring > Number of displayed digits
https://help.codesys.com/webapp/_cds_dl ... n=3.5.15.0 m
Originally created by: D. Kugler
you can use the TO_DINT funktion to throw all decimals away, so before 100.0 afterwords /100.0:
AIN01R:= TO_LREAL(TO_DINT(AIN01100.0)/100.0);
Actually there is a type inconsistency in your formula :
LREAL:=UINT_TO_LREAL(UINT (I beg))/INT*REAL
Then, REAL/LREAL are stored and interpreted (IEEE float format https://en.wikipedia.org/wiki/Double-precision_floating-point_format). That's why your values can't be exactly the same.
If you need to get back your precise value, then I would suggest working with DINT and using scaling (*100) for you math.
The type you need is called DECIMAL, but as far as I know, isn't supported in automation systems.
Originally created by: phenixrb
HI,I-Campbell
thanks for your answer, that's what I was looking for.