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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Problem in my computation result Infinity

    Hi..

    I have this function:

    Code:
    function doz(oText){
        var P27_max = document.getElementById("P27_max").value;
        //var P27_max_convert = parseFloat(P27_max) + parseFloat(1); 
        var P27_max_convert = ((parseFloat(P27_max) * parseFloat(1000)) / parseFloat(0.00) / parseFloat(12));  
        if( !isNaN(P27_max_convert) ){
        var P27_maxdoz = document.getElementById("P27_maxdoz").value = P27_max_convert.toFixed(2);
        }
    
        var P28_max = document.getElementById("P28_max").value;
       // var P28_max_convert = parseFloat(P28_max) + parseFloat(2);
        var P28_max_convert = ((parseFloat(P28_max) * parseFloat(1000)) / parseFloat(22.00) / parseFloat(12));    
        if( !isNaN(P28_max_convert) ){   
        var P28_maxdoz = document.getElementById("P28_maxdoz").value = P28_max_convert.toFixed(2);
        }
    }
    my output is Infinity..

    what's wrong in my computation :

    var P28_max_convert = ((parseFloat(P28_max) * parseFloat(1000)) / parseFloat(22.00) / parseFloat(12));

    Thank you

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by newphpcoder View Post
    my output is Infinity..

    what's wrong in my computation :

    var P28_max_convert = ((parseFloat(P28_max) * parseFloat(1000)) / parseFloat(22.00) / parseFloat(12));
    I do not see anything wrong with that expression, except that it is pointless to use parseFloat with a value which is already a floating point number.

    var P28_max_convert = parseFloat(P28_max) * 1000 / 22 /12;

    But var P27_max_convert = ((parseFloat(P27_max) * parseFloat(1000)) / parseFloat(0.00) / parseFloat(12)
    involves division by zero, which will always result in infinity (not NaN). What is the point of dividing by the fixed value zero?


    Quizmaster: How many centimeters are there is a metre?
    Contestant: Two and a half.
    Last edited by Philip M; 03-12-2012 at 02:01 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    newphpcoder (03-13-2012)


  •  

    Posting Permissions

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