# Rounding up decimal numbers

## Recommended Posts

Hi
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;
Marko

##### 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.

Regards

Denis

##### Share on other sites

Can you give us an example of the decimal value you want to round?

Joe T.

##### Share on other sites

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:

Marko

##### Share on other sites

I just wanted to know if there were a lot of decimal places to worry about.

On 11/18/2017 at 11:02 AM, sgull said:

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

Example attached.

Joe T.

Rounding example.vlp

## Create an account

Register a new account