I have a mathematical problem that I am not sure how to solve. I am trying now but still cant find a solution.

What I is doing is this:

The example is that I have a number: "129" that I will need to round down to the nearest value. The answers to these example values look like this.
How can I find a formula that can round down to nearest value like these examples ?

Round down to nearest 5 gives: 125
Round down to nearest 10 gives: 120
Round down to nearest 20 gives: 120
Round down to nearest 100 gives: 100
Round down to nearest 1000 gives: 0

Hate to say..

But ur question is not clear at all..!!

Finally got it..!! sorry..

The problem can be easily done in programmimg...!!

Hate to say..

But ur question is not clear at all..!!

Okay, I will try to explain better. What I am looking for is a formula that can round down a number to a nearest given value.

The examples below is based on the number: 129
Ex: Round down 129 to nearest 40 gives: 120 in this way:
40 + 40 + 40 = 120

The same princip follows for the below examples.

Round down to nearest 5 gives: 125
Round down to nearest 10 gives: 120
Round down to nearest 20 gives: 120
Round down to nearest 30 gives: 120
Round down to nearest 40 gives: 120
Round down to nearest 50 gives: 100
Round down to nearest 100 gives: 100
Round down to nearest 1000 gives: 0

For this problem, if you get 1, other will be simple. So focus on 1
function first.

>>Round down to nearest 5 gives: 125

Before we go further.

What happens if we say this :

Round down to nearest 5 for number 124 ?
Round down to nearest 5 for number 3 ?

Edit : I see

You have the answer in your face. All you have to do is copy it into code.

>>The examples below is based on the number: 129
Ex: Round down 129 to nearest 40 gives: 120 in this way:
40 + 40 + 40 = 120

Try to do exactly that, in code.

If we are rounding down to the nearest 10. We can do this

``````int num = 129;
int roundedDown = 1;
//round down to the nearest 10
while( roundedDown < num  - 10 ){
roundedDown  += 10;
}``````

Thanks, I add some more examples. Just tell if you need more examples. I think I am looking for an equation:

Round down to nearest 5 for number 124 gives: 120
Round down to nearest 5 for number 3 gives: 0
Round down to nearest 15 for number 47 gives: 45
Round down to nearest 30 for number 75 gives: 60
Round down to nearest 51 for number 50 gives: 50
Round down to nearest 50 for number 49 gives: 0

Wat u need to do is ....

Take the number from the User..
make sure it is integer type...

divide it by 5,10,100,1000 and store it in another integer variable..

next..u jus need to multiply the variables it the same number u divided...

print the variables...

(This is possible bcoz in C ..The decimal part of the number is Neglected in integer type...)

I can write u the program if u want...and yes i m searching the equation as well..!! cheers..!!! :D

Yes you are right, that is the solution. Though there is one detail left.

I try this for Nearest 5:

``````129 / 5 = 25.8 //Here I need to Round Down to 25 and do:

25 * 5 = 125``````

I have the Math::Round function. So the final question should be how to round down a decimal like this:

25.8 gives 25
14.2 gives 14
38.5 gives 38

Wat u need to do is ....

Take the number from the User..
make sure it is integer type...

divide it by 5,10,100,1000 and store it in another integer variable..

next..u jus need to multiply the variables it the same number u divided...

print the variables...

(This is possible bcoz in C ..The decimal part of the number is Neglected in integer type...)

Yes you are right, that is the solution. Though there is one detail left.

I try this for Nearest 5:

25.8 gives 25
14.2 gives 14
38.5 gives 38

Yaa ..I got it...

Formula : `(((The Number/5)-(rem/5))*5)`

`(((129/5)-(4/5))*5)`
`...`

Yes you are right, that is the solution. Though there is one detail left.

I try this for Nearest 5:

25.8 gives 25
14.2 gives 14
38.5 gives 38

Yaa ..I got it...

Formula : `(((The Number/5)-(Remainder(of the last div)/5))*5)`

`(((129/5)-(4/5))*5)`
`...`

Thank you very much for your help. You did solve the problem!

Nice day :)