You are invited to Log in or Register a free Frihost Account!

# fraction function

can anyone figure this out. how to use this class?

i just want to add 1/2 + 1/3 + 1/6 and get the result in x/y.

jmraker
I'm sorry that I don't know the math terms...

I'm guessing it involves finding that 6 is the largest "something" the 2nd part of the fraction can all be multiplied into and multiply the 1st part of the fraction by what it takes to multiply to the 2nd part of the number. (for 1/2) it multiplies 1*3 because 2*3=6) where it's (3/6)+(2/6)+(1/6) and 3+2+1=6 so it would be 6/6 or 1.

Yup. I'll never be able to teach math.
noah
This shouldn't be too dificult to do.

1.Multiple all bottom numbers by themselves
4. Reduce fractions

This is not the BEST way, but it is one trivially easy way to do it.
oh.. for god sake.

i know how to add, subtract, multiply and divide fraction.

this is php and mysql board, not basic elementary mathematics.

you want to talk mathematics, go request for new board.

can someone translate the comment for me? thanks.
noah
I understand. I just told you algorithm to use to create a function so you wouldn't have to use someone elses. The functions are labeled well enough that if you played around with it and treated each function like a blackbox you could probably figure it out within an hour.
i already have my own function. i even have that function call another function to get the fraction common divisor so i can "simpilfy" my fraction

it just that i found this nice php class (do you even know what class is. no, it's not about a group of students attending a specific course or lesson), and i really like to use it.

that's all.

no, i don't need you to teach me about fraction, my php function does work perfectly. it just not well written as this class.

oh, by the way, nobody need to write their own function, just google for it and you can get hundreds of it out there. that's how i wrote my own function. and among the search result is this one nice looking class.

now you know what's really going on here?
noah
haha, okay.

Sorry, I couldn't have been of more help.

In the future you shouldn't be so abusive towards people who are trying to help you.
no problem, and sorry for my abusive language. i'll be more polite next time.

 noah wrote: haha, okay. Sorry, I couldn't have been of more help. In the future you shouldn't be so abusive towards people who are trying to help you.
jmraker
This might work

 Code: \$f = array(); \$f[] = new Fraction(1, 2); \$f[] = new Fraction(1, 3); \$f[] = new Fraction(1, 6); \$maxDenom = 1; foreach(\$f as \$frac)    \$maxDenom *= \$frac->getDenominator(); \$maxNum = 0; foreach(\$f as \$frac)    \$maxNum += \$frac->getNumerator() * (\$maxDenom / \$frac->getDenominator()); \$result = new Fraction(\$maxNum, \$maxDenom); var_dump(\$result);
Helios