Advertisement

Multiplier.

Started by February 09, 2002 03:01 PM
13 comments, last by leggyguy 23 years ago
If I have a number, say 1.3, or 0.65, I need to find out what is the quickest way to turn into a full (higher, but lowest posible) number through multiplication. By full, I mean a whole number with no fraction following it. So 2 is fine, as is 106, or 1045. But 10.50 is no good. And I need to know what you have multiplied it by in order to get that whole number. How would you do this? Thanks for all input.
All I can think to do is use ceil(x) or (int)(x+0.5)
Advertisement
Sorry, you misunderstand.

What I mean is, you need to do it only through multiplication. That is why it is hard.

so 1.5, for example would become 3.0
Take the reciprocal of the decimals, and multiply the original number by that. Thats the only way I can see of doing it.

So for instance:

1.5 -> Decimal = 0.5, reciprocal = 2 -> 2 x 1.5 = 3
1.1 -> Decimal = 0.1, reciprocal = 10 -> 10 x 1.1 = 11
5.25 -> Decimal = 0.25, reciprocal = 4 -> 4 x 5.25 = 21

Get it?

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
On a side note, it took me about 10 seconds with a pencil and paper to work that out, if you just tried to do it yourself in the same way I bet you could do it just as easily.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
Thanks for that python.

It is something I shouldn''t have to ask really, but it is such a long time since I took any serious maths classes that I have gotten rustier than I thought.

It is great to have somewhere like this I can come to to get help and guidance.
Advertisement
Your suggestion isn''t quite right python_regious:

1.3 -> Decimal 0.3, reciprocal = 3.3333 -> 3.3333 x 1.3 = 4.3333

Same with 1.4, 1.6, 1.7, 1.8, 1.9.

In order to figure it out you need to multiply by 2 or 5, or some combination of the two. If the last decimal is even, multiply by 5, if it is odd multiply by 2. Repeat until it isn''t a decimal anymore.
Yep, I wasn''t quite right, it only works in certain situations. Perhaps I should have spent more time on it

Ok, I think I have it now, I don''t know whether this is what thoot suggested, but if the last decimal is odd, multiply by 10, that will be the first possible whole number. If it is even, multiply by 5. No, wait, that doesn''t work either. Oh sod it, I dunno! It is some multiple of 2 and 5, but which to find the lowest whole number is the thing.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
d=number of digits after decimal point
x=10d(number)

hope that helps.

EDIT- watch out for overflow

-potential energy is easily made kinetic-

Edited by - Infinisearch on February 9, 2002 12:19:44 AM

-potential energy is easily made kinetic-

InfiniSearch - That finds *a* solution, but not the lowest.

Take 1.5 as before, by your reckoning, it would be:

x = 10 * 1.5 = 15.

Which is not the lowest solution. The lowest is 3.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.

This topic is closed to new replies.

Advertisement