Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simplify fraction

Status
Not open for further replies.

Aarem

Programmer
Oct 11, 2004
69
US
Hello. Does anyone have a good script or link for simplifying a fraction in flash? For example, simplifying 6/3 to 2 or 3/6 to 1/2? thanks.
 
as1 solution. algorithm could be improved as some tests unnecessary

Code:
Number.isInteger = function(n) {
	return (n%1 == 0);
};
function simple(a, b) {
	for (i=1; i<a+1; i++) {
		c = a/i;
		d = b/i;
		if (Number.isInteger(c) && Number.isInteger(d)) {
			e = c;
			f = d;
		}
	}
	trace(e+"/"+f);
}
simple(4, 10);
//returns 2/5
simple(16, 48);
//returns 1/3
simple(3, 7);
//returns 3/7
simple(25, 10);
//returns 5/2
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top