如何使用jquery添加小数?

时间:2015-02-20 17:50:19

标签: jquery

我有这个if语句:

 if (price % 10 > 5) {
        newPrice = floor(price / 10) * 10 + 9.95;
    } elseif (price % 10 <= 5) {
        newPrice = floor(price / 10) * 10 + 5.95;
    }

我在5.95上使用parseInt吗?这适用于PHP但我转换为JQuery并想知道我是否必须进行任何更改?

我试了这个没有运气

if (selectprice % 10 > 5) {
   selectprice = parseFloat(floor(selectprice / 10)) *  parseInt(10) + parseFloat(9.95);
} elseif (selectprice % 10 <= 5) {
    selectprice = parseFloat(floor(selectprice / 10)) * parseInt(10) + parseFloat(5.95);
}

1 个答案:

答案 0 :(得分:1)

使用Math.floor()而不是floor()。我认为你不需要做任何其他改变。

if (selectprice % 10 > 5) {
      selectprice = Math.floor(selectprice / 10) * 10 + 9.95;
} else if (selectprice % 10 <= 5) {
      selectprice = Math.floor(selectprice / 10) * 10 + 5.95;
}