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 to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Comparing decimal numbers

    I am trouble in comparing decimal number.

    var1 = 0.25
    var2 = 0.50

    if (var1<var2)
    {
    alert("Value is less than minimum")

    }
    else
    {
    return true;
    }

    How can I make it work. Thanks for help in advance

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,284
    Thanks
    12
    Thanked 343 Times in 339 Posts
    I don’t see the problem.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,084
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Quote Originally Posted by visionweb View Post
    I am trouble in comparing decimal number.

    var1 = 0.25
    var2 = 0.50

    if (var1<var2)
    {
    alert("Value is less than minimum")

    }
    else
    {
    return true;
    }

    How can I make it work. Thanks for help in advance
    If you just trying to get the alert to display, do this:
    Code:
    if (var2 < var1)
    ...

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,010
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    A return statement must be within a function.

    Code:
    <script type = "text/javascript">
    function myFunction() {
    var1 = 0.25
    var2 = 0.50
    
    if (var1<var2) {
    alert("Value is less than minimum");
    return false;
    }
    else {
    return true;
    }
    }
    myFunction();  // to run the function
    </script>
    It is a bad idea for obvious reasons to name variables var1 and var2.
    Last edited by Philip M; 07-31-2010 at 05:08 PM.


  •  

    Tags for this Thread

    Posting Permissions

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