NaN problem

Discussion in 'JavaScript' started by greatlogix, Jan 22, 2008.

  1. #1
    Here is the function
    function showPrice2(items,def, lp){ 
    	if (items != 0){
    		ss = document.form2.color.options[form2.color.selectedIndex].value;
    		if(undefined===window.ss){
    		window.ss = '0,0';
    		}
    		if(items == '0,0,0,0'){
    			var valArray = new Array();
    			valArray[0] = 0;
    			valArray[1] = def;
    			valArray[2] = lp;
    			valArray[3] = 0;
    		}
    		else{
    			var strValue=new String(items);
    			var valArray = strValue.split(",");
    		}
    		
    			 var clr=new String(ss);
    		
    		var clrarr = clr.split(","); 
    		clrs = parseFloat(clrarr[1]);
    		endprice = Number(valArray[1]) + Number(clrs); alert(endprice);
    //............ some more code. I am getting error in above line.
    
    HTML:
    Number(clrs) is creating problem. When I pass zero (0) to it result is fine. When I pass 5.00 to it I get NaN in alert. Can somebody help me why I am getting NaN error.
     
    greatlogix, Jan 22, 2008 IP
  2. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var endprice ?
     
    maiahost, Jan 22, 2008 IP
  3. webmaster_TSU

    webmaster_TSU Peon

    Messages:
    449
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think I would pass it 5, not 5.00. 5.00 is not a whole number I guess you would say, more a float.
     
    webmaster_TSU, Jan 22, 2008 IP
  4. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #4
    I have also tried 5. I have tried every way to convert string into integer but everytime I am getting NaN.

    I am doing typecasting here still NaN ???
    I have tried pasreFloat
    I have tried var a = 1*clrs

    Nothing worked for me. :(
     
    greatlogix, Jan 22, 2008 IP
  5. webmaster_TSU

    webmaster_TSU Peon

    Messages:
    449
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well your setting clrs to a float, so maybe that is the problem? I can't test now so I'm not sure, I can't test it right now.

    Actually, I would print out the values of ss, clr, and clrs to ensure it's actually parsing into something that will convert into a number. I bet it's creating a string that can't properly convert to a number using the number function, perhaps there is a space or something.
     
    webmaster_TSU, Jan 22, 2008 IP