0

I’m trying to calculate a value by subtracting the magento subtotal of my cart from another value, let’s say 50. This is the code:

<script type="text/javascript">
function minus_number() {
        var a  = document.querySelector("#spend");
        var first_number = '50.00';
        var second_number = '<?php echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); ?>';
        var result = parseInt(first_number).toFixed(2) - parseInt(second_number).toFixed(2);
        a.innerHTML = result.toFixed(2);
    }
window.addEventListener("load",minus_number());
</script>

Now it kind of works, but the result isn’t right. I think the issue is that the magento subtotal doesn’t include decimals? So if let’s say the subtotal is 6.98 the result is 44.00 so I assume it only subtracts the 6?

0

Try with parseFloat() instead of parseInt(). Everything else should be working ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.