Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Thats my jquery code. And the variable "procenti" always return like 92.3076923076923 % long decimal number. I would like that number to be without the decimals, only 92%. I tried .toFixed() method but it doesnt works.

When the equation is like procenti=(3/10)*100; == 30%, the number in html looks just what i want without decimals.

for(var i=1; i<14; i++){

  var zmage=parseFloat($('#zm'+i).text());
  var odigrane=parseFloat($('#od'+i).text());
  var procenti=0;


  if(zmage == 0){
      $('#pr'+(i)).html(0 + ' %');
  }
  else{
      procenti=(zmage/odigrane)*100;
      $('#pr'+(i)).text(procenti + ' %');
  }

  }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
169 views
Welcome To Ask or Share your Answers For Others

1 Answer

round() function will round off value.

Math.round(procenti);

Otherwise there are another functions ceil() & floor()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...