ID:173514
 
I'm not what one would call a, "fan of math (who is?)" but I've tried using some hack and slash method of converting percentages out of 100 into correct fraction form. But, no go :-\ Anyone have any suggestion's or insights on how I would go about doing this?
Divide by 100.
In response to Garthor
Wouldn't that just give me the same number percent except the decimal's just moved over by one? An example of what I'm trying to achieve would be like this:
Percentage Format:
25/100
Fraction Format:
1/4

I want to convert the 25/100 percentile to the lowest terms of the fraction to use in a text string, to use as classification.
In response to Goku72
Goku72 wrote:
Wouldn't that just give me the same number percent except the decimal's just moved over by one? An example of what I'm trying to achieve would be like this:
Percentage Format:
25/100
Fraction Format:
1/4

I want to convert the 25/100 percentile to the lowest terms of the fraction to use in a text string, to use as classification.

I'm not sure how precise you want this, but this would work for the most part;
mob/verb/Fraction(n as num)
src << "1/[100 /n]"


Hope it helps.

[Edit] Just realized a pointless peice in my snippet.

~>Volte
In response to Volte
Unfortunately, that breaks down with values over 100%, and gives decimals when using numbers that don't go into 100 evenly.

A more thorough method:


First seperate the numerator and the denominator.

Then, go through all prime numbers between 2 and the square root of the smaller number. You can just go through odd numbers (and two) for simplicity.

Check to see if the numerator % the number and the denominator % the number are bother 0.

(% is the modulo operator, A % B is the remainder of A / B)

If they are, divide and repeat the process until finished.


Because the demoninator will always be 100 in your case, the process is greatly simplified. 2 and 5 are the only two prime numbers that go into 100 evenly.