Hi all, I am returning to using PLC's after not having used them for some 20 odd years. My have things changed!
I'm new to CodeSys and am writing a simple program in ST to learn the IDE and test my old skills.
Clearly they're not very good.
I am try to divide two declared signed integer variables and store in a REAL variable i.e.140 / 16
The answer should be 8.75 but when I run the program in simulation the real variable shows only the 8 with no decimal place or anything thereafter.
Can anyone help with what am I doing wrong please?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Embarrassingly I just realised the same just before you posted your kind reply!
Its been a while and sometime it's a case of "If you don't use it.....you lose it!"
Hopefully with more practice some of it will come back.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Newbie Question!
Hi all, I am returning to using PLC's after not having used them for some 20 odd years. My have things changed!
I'm new to CodeSys and am writing a simple program in ST to learn the IDE and test my old skills.
Clearly they're not very good.
I am try to divide two declared signed integer variables and store in a REAL variable i.e.140 / 16
The answer should be 8.75 but when I run the program in simulation the real variable shows only the 8 with no decimal place or anything thereafter.
Can anyone help with what am I doing wrong please?
Hi Biggles!
To get a REAL result, you have to do the calculation in REAL. So just convert the SINTs into REAL and do the calculation then:
rResult: REAL;
siInput1: SINT;
siInput2: SINT;
rResult:= SINT_TO_REAL(siInput1) / SINT_TO_REAL(siInput2);
That should work!
Alfred
Thanks Alfred!
Embarrassingly I just realised the same just before you posted your kind reply!
Its been a while and sometime it's a case of "If you don't use it.....you lose it!"
Hopefully with more practice some of it will come back.