A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: number values with leading zeros mystery....

  1. #1
    Senior Member
    Join Date
    Mar 2003
    Location
    wishconsin
    Posts
    151

    number values with leading zeros mystery....

    this is spooky...

    i can do this:
    myArray = [];
    myArray.push(01);
    trace(myArray[0]) //returns 1

    and this:
    myArray = [];
    myArray.push(10);
    trace(myArray[0]) //returns 10

    but i can't do this?
    myArray = [];
    myArray.push(09);
    (won't publish)

    why?


  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    In actionscript (and in C), numbers with leading zeros are considered to be in octal (base 8). 8, 9 is not a valid octal digit, so 08 and 09 generate syntax errors.

    Check this out:

    trace(01);
    trace(02);
    trace(03);
    trace(04);
    trace(05);
    trace(06);
    trace(07);
    trace(010); // says 8
    trace(011); // says 9
    trace(012); // says 10

    Incidentally, although this feature has been common in C-based languages since the inception of C, I know of no practical use for octal these days.

    I almost always use either decimal (123) or hexidecimal (0xabc).

    - jim

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Location
    wishconsin
    Posts
    151
    woah far out man... octal

    thanks for that explaination, that was really perplexing me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center