toFixed(0) and Date.getTime() bug

I’ve been able to reproduce a bug several times with the Number.toFixed(0) method in that it returns a “.” . Also from what i understand the Date.getTime() should return an int but sometimes it returns a decimal.

So i did a quick exercise to figure out what percentage of returns have this error and i found it’s around the 10% of the cases.

  1. var score:uint = 0;
  2. var totalTests:uint = 1000;
  3. for(var i:uint=0;i<totalTests;i++){
  4. var p:Number = Math.random() * 10;
  5. if(p.toFixed(0).indexOf(".") != -1) score++;
  6. }
  7. trace ((score * 100) / totalTests);

It returns me around 8.7 and 10.1 along several calls.

I’m currently writing a workaround method for this.

Also, while developing some customer’s AS3 api i noticed that the Date.getTime() was returning a decimal number so i extended my test cases to include this and found that i was correct. I don’t know exactly in which situations this occur but i can assure it’s happening. Has anyone experienced this before?

— fernando