user892134
user892134

Reputation: 3224

How to add decimals with jquery?

i have this if statement:

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

Do i use parseInt on 5.95? This works in PHP but i'm converting to JQuery and wondering if i have to make any changes?

I tried this with no luck

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

Upvotes: 0

Views: 45

Answers (1)

Vijay Purush
Vijay Purush

Reputation: 331

Use Math.floor() instead of floor(). I don't think you need to make any other changes.

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

Upvotes: 1

Related Questions