# Thread: Help with finding nearest multiple of 250

1. Member Join Date
Nov 2012
Posts
40
Rep Power
0

## Help with finding nearest multiple of 250

I have an assignment to take the number of pints of popcorn a farm produces and divide it by the number of acres on the farm. After that, I need to
figure out the nearest factor of that number and 250. For example, if I have 567 pints/acre, I would need to round it down to a multiple of 250, so this
would return a value of 2, and so on. I've been using the % operand, but I can't quite figure out how to round it down to the proper multiple.
Here's a bit of my code to show what I mean.
Java Code:
```		pintAcre = pints / acres;
while(pintAcre%x == 250){
x++;
pintFactor[x] = pintAcre;

}```
X would continually increase in the loop to find the product of the math. But unfortunately, it only returns 0. I'm not very experienced with %, and I'm not sure how to go about it. Thanks for any help.  Reply With Quote

2. Senior Member Join Date
Nov 2012
Posts
257
Rep Power
8

## Re: Help with finding nearest multiple of 250

Its been a while since i did something like this but give it a go :/

You could use mod (%) and deal with the remainder: This probably isn't the most efficient way but it works for me

This is an example of dealing with remainders, i used different variables just to show you, you will need to adapt this to suit you

Java Code:
```                int pintAcre = 500;
int testRU = 375;
int testRD = 11123;

if((pintAcre % 250) == 0){
System.out.println("Exactly multiple of 250: " + pintAcre);

}
if((testRD % 250) <= 124){
int x = testRD - (testRD % 250); //if remainder is below half way then just remove the remainder from the value, which will become a rounded down multiple of 250
System.out.println("rounded down: " + x);
}
if((testRU % 250) >= 125){
int y = testRU - (testRU % 250) + 250 ; // if remainder is above or equal to half way, then take the number subtract the remainder from it so you get to the rounded down multiple of 250, then add 250 to it, which rounds it nearest 250
System.out.println("Rounded up : " + y);
}```
Prints:

Exactly multiple of 250: 500
rounded down: 11000
Rounded up : 500

Example of the round up method:

375 % 250 = 125.

125 is half way do round up:

375 - (375 % 250) = 250

250 + 250 = 500.

375 to nearest 250 = 500
Last edited by monkeyjr97; 05-11-2013 at 10:26 PM.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•