Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't add two decimal numbers using jQuery

Tags:

People also ask

How do I get 2 decimal places in jQuery?

$("#diskamountUnit"). val('$' + $("#disk"). slider("value") * 1.60);

How do I force two decimal places in JavaScript?

Use the toFixed() method to format a number to 2 decimal places, e.g. num. toFixed(2) . The toFixed method takes a parameter, representing how many digits should appear after the decimal and returns the result.

How do you sum decimals in JavaScript?

To add two decimal numbers in JavaScript use the toFixed() function to convert it to a string with some decimal places shaved off, and then convert it back to a number.


I am trying to add two decimal values but the returned sum is pure integer. What is wrong? I can't find it. any help will be welcome.

jQuery(".delivery-method #ship_select").change(function(){
    var cost = jQuery(this).val(); 
    jQuery("#delivery_cost").val(cost); //returns 20.00
    var tot = parseInt(cost) + parseInt(total); //total returns 71.96
});

With the code i am getting only 91 and not 91.96