Rounding to nearest 10th Control Logix

remullis

Member
Join Date
Oct 2012
Location
Georgia
Posts
179
I am needing some assistance on rounding to 10th in control logix.


I am reading a real number for density out of the meter of i.e 45.23324. I would like to round this to 45.2 and move this number to an AO for an LED Display. The TRN function takes me to the nearest whole number and the same with a DINT which rounds to a whole number. Thanks in advance!
 
MUL REAL 10 Temp_DINT This will give you 452

DIV Temp_DINT 10 REAL_2 This changes the decimal place back to where it was.

EDIT: For more decimal places multiply & divide by larger numbers. X/|100=0.01 X/|1000=0.001
 
Last edited:
Just be aware that rounding in control logix handles rounding a little differently when it comes to values with a .5 on the end. It rounds them to the nearest even integer.

1.4999 rounds to 1
1.5 rounds to 2
2.5 rounds to 2
2.5001 rounds to 3
3.4999 rounds to 3
3.5 rounds to 4
4.5 rounds to 4

And so on. I say this, because it may catch you out if you use the methods above, e.g. if your number is 3.45. You may be expecting the answer to be 3.5, but...

3.45 * 10 = 34.5
34.5 rounds to nearest even integer, i.e. 34
34 / 10 = 3.4
 

Similar Topics

I've done a little research on this but still haven't found an answer. I'm trying in RSLogix 500 on a SLC 5/04 to calculate an integer I want to...
Replies
11
Views
4,636
Hi all, I'm connecting several 4-20mA sensors together in parallel (only one shown below) The enclosure is ABS plastic with metal backplate DAQ...
Replies
5
Views
273
I have Rhino 120 to 24 dc power supply and it has 2 Positive and 2 negative terminals on the DC side but no ground terminal. Should I connect one...
Replies
9
Views
434
Hi, Our customer has bought a machine a CNC wood cutting machine. It states that it need a seperate 16mm2 EMV"ground" in addition to our 5G16mm2...
Replies
2
Views
602
I have a Beckhoff PLC with many AI modules. Most devices are loop powered using the same +24 VDC power as the Beckhoff Bus Coupler and all is...
Replies
5
Views
668
Back
Top Bottom