开发者

How do I convert 10 to .10 or 10% in javascript?

开发者 https://www.devze.com 2023-02-22 16:44 出处:网络
The third-party is feeding me 10 percent as the number 10. In my code how do I move the decimal 2 places 开发者_运维百科over for the variable itemDiscountPercent?

The third-party is feeding me 10 percent as the number 10. In my code how do I move the decimal 2 places 开发者_运维百科over for the variable itemDiscountPercent?

        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);

    }

So instead of getting 299.8 for a line item with quantity 2, I need it to be 2.99 so I can subtract it later in the code.


divide by 100.

var dec = itemDiscountPercent / 100;


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);

}
0

精彩评论

暂无评论...
验证码 换一张
取 消