Jump to content

Rounding up decimal numbers

Recommended Posts

This is my second project, and I have a question.  I'm using V430-J-34 (provided by user...)

Whats the best way to round up or round down decimal numbers to whole numbers?

Currently I'm using simple linealization to convert result of some math to some normal number.

Problem is there is whole excel table of math to do, that I am currently working on to be in plc
example: Fx=IF(AND(C6>=130;C6<220);C6-20;IF(AND(C6>=220;C6<310);(C6-40)/3+G6;IF(AND(C6>=310;C6<400);(C6-40)/4+G6;IF(AND(C6>=400;C6<490);(C6-40)/5+G6;IF(AND(C6>=490;C6<=600);(C6-40)/6+G6;)))))

C6 is input user makes (before in excel table, now it will be on display); G6 is just some result from previous math

So for every "IF" I write  conditions, then math formula. Then linearization.
Then I can use that for information to compare whit encoder input to stop the motor and do some action (drill, cut, pierce...)

And I still have not connected and configured encoder, but that will be question for another post if I don't figure it out..

Sorry for any mistakes, English is not my main. 
Best regards;

Link to comment
Share on other sites

Hi Marko

Normally the decimal portion is the result of a divide function. You probably do all of your math with MI whole numbers and then divide to get the decimal portion.

when you divide an MI the portion after the decimal point gets stored into SL4.

You can then use a simple compare to determine if this value is big enough to be rounded up or not.

You must use SL4 directly after each math function as it will be updated with each divide function.

Hope this helps.




Link to comment
Share on other sites

Thank you for your response.

Sgull, you are right. I am using MI  whole numbers. And all for decimals are result of simple divide.

Joe T., Simplest example that I have is ( A - 14.1 ) / 7.2.  . A is MI input from user. Result is number of pieces  machine needs to make (also MI).  If result is for example between 3.5 and 4.4, result should be corrected to 4 pieces.
Different example is ( A - 40 ) / 3 + B ; A is MI input from user, B is result from previous math (also MI), result is place where tool should pierce the material. This will be compared whit input from encoder. Needs to be precise to about 1/10 mm. I don't know should I even try to round it up.

Best Regards:


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...