# Rounding a decimal number

## Recommended Posts

Hi everyone,

I have a pretty easy to answer question for most of you:

I'm developing a program in wich an operator writes in a v130 the quanity of m3 of concrete wich are gonna be produced in a little plant.

The idea is that the operator writes these m3 in a Display in a variable numeric field, which willl have the format: 3.2 (999.99 m3).

I need to process this number to set the number of batches (mixes) of the plant, due to this plant has the capacity to produce only 1 m3 batch at time.

So if for example the operator wants to produce 2.25 m3 of concrete, the number of batches will be 3.

I need you to help me about how to set this number of batches??, if the number of m3 should be rounded.

For the time being, I set the m3 as a numeric variable linked to an MI.

Thank you so much.

##### Share on other sites

• MVP 2014

My quick answer is as follows:

1. Perform integer divide, m3 DIV 100, store the result

2. Perform modulus divide, m3 MOD 100 and perform the following comparison

3. IF m3 MOD 100 = zero, THEN

number of batches = m3 DIV 100

OTHERWISE

number of batches = (m3 DIV 100) + 1

I hope this makes sense, and anyone is of course welcome to suggest an alternative.

##### Share on other sites

• 3 weeks later...

My quick answer is as follows:

1. Perform integer divide, m3 DIV 100, store the result

2. Perform modulus divide, m3 MOD 100 and perform the following comparison

3. IF m3 MOD 100 = zero, THEN

number of batches = m3 DIV 100

OTHERWISE

number of batches = (m3 DIV 100) + 1

I hope this makes sense, and anyone is of course welcome to suggest an alternative.

Thank you so much.

Im trying to get this in next way:

In a HMI display I put 2 MI values wich are filled by the operator. The first one, for the integer quanity and in the second MI the operator will write de floating quanity of these m3.

Then in ladder if the second MI is greater than zero, the total of batches will increase in 1 unit.

Am I ok?

Thank you so much Simon.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×