Reverse Number Function


function PrintReverse(i:Number, r:Number = 0):Number {
	trace(i+" : "+r);
	return (i<1) ? r : PrintReverse((i-i%10)/10, Math.floor(r*10+(i%10)));
}

trace("output: "+PrintReverse(123456789));

/* OUTPUT
123456789 : 0
12345678 : 9
1234567 : 98
123456 : 987
12345 : 9876
1234 : 98765
123 : 987654
12 : 9876543
1 : 98765432
0 : 987654321
output: 987654321
*/

Quick code… should work in AS2 or AS3 (using the Number datatype above or using int). If you feed it a decimal, it’ll only output the reversed integer part, it discards the fractional part (ie. put in 12345.6789 and it’ll output 54321).