vendredi 9 novembre 2018

checkbox format number javascript

I have a problem: when I sum the price (the base price is 500.000, and I want to sum 20.000) it change the total to 520 and not 520.000. and when i sum the othet price (1000 + 17,78) the price is licke 27.780 i think i need to format the number but I don't know how. Can someone help me?

Please see the website link

here's the code:

//sommo rata e prezzo dei plus a quelli del DB
var basicPrice_rata = 1000 ; // This is how we start
var basicPrice_prezzo = 50000 ; // This is how we start
    
$(document).on('change', getCheck);
    function getCheck() {
    var currentPrice_rata = basicPrice_rata; // every time
    CurrentPrice_rata = basicPrice_rata;
    var currentPrice_prezzo = basicPrice_prezzo; // every time
    CurrentPrice_prezzo = basicPrice_prezzo;
        plus = [],
        total_rata = 1000;
        total_prezzo = 50000; 

    $('input[type="checkbox"]:checked').each(function(i, el) {

            total_rata += parseInt($(el).data('rata'));
            total_prezzo += parseInt($(el).data('prezzo'));

            //console.log(total_rata);
            plus.push($(el).data('name')); // get the label text
     
    });


//inserisco i nomi dei plus nella riga di testo
 $("#plus-display").text(plus.join(", "));
    
//inserisco le rate sommate  nei div corrispondenti
 $('#rata-display-2').text(total_rata +" €");
    
//inserisco i prezzi sommati  nei div corrispondenti
 $('#prezzo-somma').text(total_prezzo +" €");
 }
<script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript" ></script>


<input type="checkbox" data-rata="134.24" data-prezzo="20000" id="posto-auto" name="posto auto" data-name="posto auto" class="check-plus w-checkbox-input">
<input type="checkbox" data-rata="17.78" data-prezzo="5000" id="posto-moto" name="Posto moto" data-name="Posto moto" class="check-plus w-checkbox-input">
<input type="checkbox" data-rata="134.24" data-prezzo="40000" id="box-auto" name="Box auto" data-name="Box auto" class="check-plus w-checkbox-input">

<div id="rata-display-2" class="prezzo-checkout">1000 €</div>

<div id="prezzo-somma" class="text-checkout color bold">500000 €</div>

<div id="plus-display" class="text_piccolo black checkout">Interior Pack Incluso nel prezzo</div>



Aucun commentaire:

Enregistrer un commentaire