A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [MX04] Check for decimal?

  1. #1
    steals free argos catalogues
    Join Date
    Oct 2006
    Location
    Manchester, England
    Posts
    77

    [MX04] Check for decimal?

    Is there a way in actionscript to check if a number has a decimal in it? I've tried making the numbers strings and doing indexOf(".") but it didn't work :S

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    You could do something like this:
    code:

    var num=4.2;
    var min=Math.floor(num);
    var max=Math.ceil(num);

    if(num>min && num<max){
    trace("decimal");
    }



    K.

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    ..and if u wanna use the string method

    Code:
    var num=4.2;
     
    if(String(num).indexOf(".") != -1){
       trace("decimal");
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    steals free argos catalogues
    Join Date
    Oct 2006
    Location
    Manchester, England
    Posts
    77
    thanks both of you

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