ear-fung.us I’m a programmer. I’m also pro-grammar.

3Feb/100

The Cartoon That Shaped My Childhood

I had a VHS tape of the program Donald in Mathmagic Land that I can remember watching all the time as a child. It's a wonder if you've never heard of it since it was one of the most popular educational films ever made by Disney.

This little 27 minute cartoon introduced me to topics such as music theory, the golden ratio, geometry, and I feel most importantly: the concept of infinity.

Thanks to the wonder of the internet, you can now watch the program in its entirety on youtube, but I've conveniently embedded it here for you to watch!

Mathematics is the alphabet with which God has written the universe.

-Galileo Galilei

16Apr/089

Flash’s Built-in Rounding Function is Severely Limited

Now that I'm working more and more in Flash ActionScript 3 I'll be posting some of my findings about it here.

My first AS3 related post is about the Math.round() function. This function will only round to a whole number (int). What if I have 3.74257444 and need a result of 3.74 instead of what Math.round() would give me: 4?

Well, here's the solution:

function roundDecimal(num:Number, places:Number):Number
{
return int( (num) * Math.pow(10, places) ) / Math.pow(10, places);
}

This function will return the specified amount of decimal places rounded correctly.

Example usage:

var myNumber:Number = 3.74257444;
trace(roundDecimal(myNumber, 2)); //Returns 3.74
trace(roundDecimal(myNumber, 3)); //Returns 3.743
trace(Math.round(myNumber)); //Returns 4

I hope this helps anyone looking for a similar solution.

[via]