Javascript总是返回浮点数 [英] Javascript always returns float numbers

查看:124
本文介绍了Javascript总是返回浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我的jquery代码。并且变量procenti总是返回92.3076923076923%长十进制数。我想这个数字没有小数,只有92%。我尝试了.toFixed()方法,但它不起作用。

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.

当方程式像procenti =(3/10)* 100时; == 30%,html中的数字看起来就像我想要的没有小数。

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 + ' %');
  }

  }


推荐答案

round()函数将舍入值。

Math.round(procenti);

否则还有其他功能 ceil()& floor()

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

这篇关于Javascript总是返回浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆