Dint/Real Calculations

Join Date
Nov 2011
Location
Ireland
Posts
182
I have a Value that is a MD1000 i.e Dint. I want to divide this value by 2. the MD1000 value may be any integer between 1 and 600. However when i divide a random value by 2 e.g 245/2 = 112.5. however i dont get the decimal of 0.5 i only get a whole number of 112 or 113. is there any way of including the decimal point in the division calculation?
 
Dividing by 2 is integer division - you won't get a fraction with integer division. Try multiplying by .5 to force a floating point computation. Make sure the destination address is a floating point type.
 
If your distination is in the form of a real then the answer will be a real. I checked this on a 5000 platform.
Divided Source A: 245(DINT) by 2. Destination: 122.5 (REAL)
 
I am using a Siemens S71200 PLC. I am wondering if i used a Convert Block to change the MD1000 Dint to a real and then divide by 2?

as the values are double integers i am not sure if the MUL block will allow a 0.5 input as you must select the data type on the block itself

Thanks for the reply
 
It depends on the system you're working in.

In ControlLogix, the destination data type determines how the calculation is done.

In other systems, you might have to convert your Dint to a Real, then do a Real divide using a Real constant of 2.0 into a Real destination.

Edit:

I'm pretty sure that Siemens is one of those that forces data types to match before you do an operation. So convert to real, then divide.
 

Similar Topics

Situation: Single [EQU] instruction with single [OTE] on a rung, nothing else/simple. [EQU] operand(A) is a real number data type...
Replies
16
Views
2,557
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,402
I have been working on an existing project for some time now and restructured the whole program into POUs instead of a singular main. Everything...
Replies
18
Views
3,188
Greetings fellow PLC programmers, I know there is a simple way to get the system date time of the RSLogix system. But, is there then a way to...
Replies
12
Views
8,389
I'm being directed to fill process values into an array of DINTs. A portion of the REAL values got copied into 2 DINTs each, but there are more...
Replies
2
Views
2,202
Back
Top Bottom