Divide an unknown number in half?

levitate

New member
Joined
Jul 1, 2013
Messages
1
How do I divide an unknown number in half?

Like a number that would always return half of the value of the original unknown number.
Im looking for an operation like: x / This.value = half of x, so I can apply it to all the possible values x could be.

Im building a random generator, that will pick a number from 1 and 10, and then I want it to get half of that number.

Its a little confusing, I honestly have no idea how to explain it better, I know its possible, because iv seen a coder do it before a while back, I just dont remember how to, and dividing by 2 will give me a decimal. I need a whole number.

Thank you in advance if anyone can answer this.
 
How do I divide an unknown number in half?

Like a number that would always return half of the value of the original unknown number.
Im looking for an operation like: x / This.value = half of x, so I can apply it to all the possible values x could be.

Im building a random generator, that will pick a number from 1 and 10, and then I want it to get half of that number.

Its a little confusing, I honestly have no idea how to explain it better, I know its possible, because iv seen a coder do it before a while back, I just dont remember how to, and dividing by 2 will give me a decimal. I need a whole number.

Thank you in advance if anyone can answer this.
Your problem is that you have not defined exactly what you want to do.

If you divide 9 by 2, you will not get a whole number so obviously what you SAY you want to do is impossible.

However, there are many ways to reduce whole numbers in the range from 1 through 10 to the whole numbers 1 through 5 for example.

How to do it in a computer depends on your programming language. Most have floor and ceiling functions.

\(\displaystyle floor\left(\dfrac{9}{2}\right) = 4.\)

\(\displaystyle ceiling\left(\dfrac{9}{2}\right) = 5.\)

\(\displaystyle floor\left(\dfrac{8}{2}\right) = 4.\)

\(\displaystyle ceiling\left(\dfrac{8}{2}\right) = 4.\)

\(\displaystyle floor\left(\dfrac{10}{2}\right) = 5.\)

\(\displaystyle ceiling\left(\dfrac{10}{2}\right) = 5.\)
 
Why does a decimal number like 4.5 cause an issue for you? What are you subsequently going to do with the values 1/2, 2/2, 3/2, ..., 8/2, 9/2, 10/2?
 
Top