# Finding lowest number to multiply a fraction and get a whole I am trying to find the multiplier for a fraction that will let me get a whole number. So trying to solve c=a xx b Where a is a number like 1.6 or 0.7 or 5.24 Where b is the lowest number that a can be multiplied by to make c a whole number. The use case is in a game I am programming the currency is only in whole numbers of a single denomination (single gold coins) if the player wants to sell a quantity of items that are worth a fractional value like 1.6, how many must they sell so they can receive a whole number without throwing out the fractions.

Leia Hood 2022-08-15 Answered
Finding lowest number to multiply a fraction and get a whole
I am trying to find the multiplier for a fraction that will let me get a whole number.
So trying to solve $c=a×b$
Where $a$ is a number like $1.6$ or $0.7$ or $5.24$
Where $b$ is the lowest number that $a$ can be multiplied by to make $c$ a whole number.
The use case is in a game I am programming the currency is only in whole numbers of a single denomination (single gold coins) if the player wants to sell a quantity of items that are worth a fractional value like $1.6$, how many must they sell so they can receive a whole number without throwing out the fractions.
You can still ask an expert for help

Expert Community at Your Service

• Live experts 24/7
• Questions are typically answered in as fast as 30 minutes
• Personalized clear answers

Solve your problem for the price of one coffee

• Available 24/7
• Math expert for every subject
• Pay only if we can solve it

## Answers (2)

Brooks Hogan
Answered 2022-08-16 Author has 18 answers
Multiply $a=\frac{8}{5}$ by $b=5$ to get
$c=\frac{8}{5}\cdot 5=8$
When a rational number is expressed as a fraction $\frac{n}{d}$ that is fully reduced meaning $gcd\left(n,d\right)=1$, with (n, numerator; d, denominator, each an integer,) then we have

and so
$c=\frac{n}{d}\cdot d=n$
That is, any rational number expressed as a fully reduced fraction where the numerator and denominator are co-prime, then the lowest integer value for $b$ is given by $bd$, where $d$ is the denominator of the fully reduced fraction = $a$
###### Not exactly what you’re looking for?
Mark Elliott
Answered 2022-08-17 Author has 6 answers
I'd suggest this algorithm: multiply by $10$ repeatedly until you have an integer. You can now write your decimal as a fraction: $\frac{k}{{10}^{n}}$. Then, use any factorization algorithm to find the greatest common divisor of $k$ and ${10}^{n}$, and divide both the numerator and denominator by that. This puts the fraction in lowest terms, and now the denominator is the number you wanted.
For the record: This is a horribly inefficient algorithm. If you need it to be fast (for example, if you're trying to do billions of these calculations) you'll want to do something else. But it'll work if you're only trying to do it a hundred times a second, or something like that.
###### Not exactly what you’re looking for?

Expert Community at Your Service

• Live experts 24/7
• Questions are typically answered in as fast as 30 minutes
• Personalized clear answers

Solve your problem for the price of one coffee

• Available 24/7
• Math expert for every subject
• Pay only if we can solve it