Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    type verification

    is there a function that checks if the value of givven string is a "float"?

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there may be a better way than this, but..
    Code:
    function is_float(str) {
        return /^[0-9]+\.[0-9]+$/.test(str);
    }

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up thanks

    it works...

    is there a way to know how many digits are to the right of the point.

  • #4
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    Code:
    function countdecs(a){return String(a).split(".").pop().split("").length;}
    alert(countdecs(234.2309482309482309));


  •  

    Posting Permissions

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