第三方给我10%的数字。 在我的代码中,如何为变量itemDiscountPercent移动小数位2?
if (boolActive)
{
itemDiscountPercent = Math.percent(ogCookie.products[i].discount_percent);
itemPrice = ogCookie.products[i].price;
itemQty = ogCookie.products[i].quantity;
if (itemQty > 1)
{
itemDiscountPercent = itemDiscountPercent * itemQty;
}
priceDiscount = itemPrice * itemDiscountPercent;
alert(itemDiscountPercent);
alert(itemPrice);
alert(priceDiscount);
}
因此,对于数量为2的订单项而不是299.8,我需要它为2.99所以我可以稍后在代码中减去它。
答案 0 :(得分:3)
除以100。
var dec = itemDiscountPercent / 100;
答案 1 :(得分:1)
if (boolActive)
{
itemDiscountPercent = ogCookie.products[i].discount_percent;
itemPrice = ogCookie.products[i].price;
itemQty = ogCookie.products[i].quantity;
//priceDiscount = itemPrice * itemQty * itemDiscountPercent / 100;
priceDiscount = Math.round(itemPrice * itemQty * itemDiscountPercent - 0.5) / 100;
alert(itemDiscountPercent);
alert(itemPrice);
alert(priceDiscount);
}