mardi 22 septembre 2015

isNaN() javascript, number with 2 commas

I'm working with percentage and the setInterval() so I have a

var intervalId;
function randomize(){
   var prc = $("#prc").val();
   var c = 0 ;
   if (!intervalId){
      intervalId = setInterval(function(){
          c = c + 1;
          var attempt = Math.random() * 100;
          if (attempt <= prc){
              clearInterval(intervalId);
              intervalId = false;
              console.log(attempt);
          }
      }, 100);
   }
}

But actually if the user set the #prc input to 50.345.34, the attempt <= prc condition always returns true. I tried to console.log(isNaN(prc)) when this input is set to a number like 50.345.34 and it always returns false.
Why is it considered as a numeric value ?




Aucun commentaire:

Enregistrer un commentaire