Easy way to round up

hackj0632

Member
Join Date
Jul 2009
Location
wi
Posts
33
I'm looking to take a real and round up to the next integer. I have a working test section of code already, but was curious if this could be done in a lot fewer steps.

What I have so far is a one-shot check to take Position_test_real convert to it.

If Test_To_Int is less than Test_TO_Real then Test_TO_int is moved to nextposition_INT.

If Test_To_Int is greater than Test_TO_Real then add one to ADD_One_Position is moved to nextposition_INT.

Looking forward to the help

Attached is a zipped JPEG.
 
Add .5 destination an integer, if your PLC supports that kind of math.

That will not work on for all numbers on Logix5000 systems.

They use the "Round-To-Even" method when a REAL needs to be stored in an integer destination.

If the REAL is 4.0 and you add 0.5 to it, to get 4.5, when that is stored back into an integer it goes to 4

If the REAL is 5.0 and you add 0.5 to it, to get 5.5, when that is stored back into an integer it goes to 6

i.e. you can never get an "odd" result, the rounding method always goes to the nearest "even" number.

This will only occur when the REAL is xxx.0 (exactly), so could easily be trapped before doing the ADD and MOV as you suggested.

EDIT: I see it is MotionWorks from the attached .ZIP file. I have no idea how rounding is performed on that platform...

2014-05-25_162712.jpg
 
Last edited:

Similar Topics

See picture. I want to add a rung (magenta) into the existing code. Can't figure out how to do this. I select a -||- , right? When I drag/drop...
Replies
21
Views
1,774
Hi All, On my site, the standard template for storing recipes in the PLC is to create a tag called PartRecipe which is an 2D array - for example...
Replies
4
Views
1,461
I would like to do change a kinetix drive, so i believe i just have to put the IP address in the new kinetix and just connect right? Do I need to...
Replies
1
Views
1,193
Hey all, I am trying to check in logix designer in emulator and I need to check the hmi alarms by toggling bits to activate an alarm . But...
Replies
4
Views
2,061
Good afternoon guys, I have a basic question on the bubble level in the picture attached. This is probably really easy, but I don't get it, haha...
Replies
11
Views
3,331
Back
Top Bottom