Добрый день, имею калькулятор на
сайте
Мне нужно сделать, чтоб Общая стоимость 3000 р. (допустим). Автоматический убирала 2 последних знака. И станвоился 30 р.
То бишь переводил с Тысячных в десятки.
В калкьуляторе стоит
<span name="symma" id="spCostTotal" class="all-cost-summ">3000</span>
В JS сама функция подсчёта:
// ---------------------------------------------------------------------------------------------------------------------
function viewCostTotal(costDefault, isPeriodCostChange) {
// Save default
costDefault = roundDown10(costDefault);
document.getElementById("iptCostDefault").value = costDefault;
if (document.getElementById("iptEnterPromo") != null) {
$.ajax({
async: false,
method: "GET",
url: ajaxPromoUrl,
data: {
"promoCode": document.getElementById("iptEnterPromo").value,
"costDefault": costDefault,
"orderId": orderId
}
}).success(function(msg) {
var costPromo = parseFloat(msg);
if (costPromo != 0) {
if (document.getElementById("divViewPromo") != null)
document.getElementById("divViewPromo").innerHTML = '';
document.getElementById("iptCostDiscount").value = costPromo;
} else {
document.getElementById("iptCostDiscount").value = 0;
}
});
}
// Initialize
var costBalance = roundDown10(document.getElementById("iptCostBalance").value);
var costDiscount = roundDown10(document.getElementById("iptCostDiscount").value);
var delivery = Number($("#spCostDelivery").text());
// Calculate
var costTotal = roundDown10(costDefault - costDiscount - costBalance + delivery);
if (costTotal < 0) costTotal = 0;
// View
document.getElementById("trCostDefault").style.display = (costBalance != 0 || costDiscount != 0) ? '' : 'none';
document.getElementById("trCostBalance").style.display = costBalance != 0 ? '' : 'none';
document.getElementById("trCostDiscount").style.display = costDiscount != 0 ? '' : 'none';
// Display
document.getElementById("spCostDefault").innerHTML = roundDown10(costDefault);
document.getElementById("spCostBalance").innerHTML = costBalance.toString();
document.getElementById("spCostDiscount").innerHTML = costDiscount.toString();
document.getElementById("spCostTotal").innerHTML = roundDown10(costTotal);
if (isPeriodCostChange) {
timeTotalMinute = document.getElementById('iptTimeTotalMinute').value;
var currentCost = timeTotalMinute / 60 * priceHourDefault;
for (var i = 0; i < aPeriod.length; i++) {
var cost = roundDown10(currentCost - (currentCost * aPeriod[i].percent / 100));
document.getElementById("prd-" + aPeriod[i].id).value = cost;
document.getElementById("spPeriodCost-" + aPeriod[i].id).innerHTML = cost.toString();
}
}
if (document.getElementById('btnPay') != null)
document.getElementById('btnPay').innerHTML = messageButtonCash + ' ' + roundDown10(costTotal) + currentCurrency;
}
// ---------------------------------------------------------------------------------------------------------------------
$(function() {
var typingTimer;
var doneTypingInterval = 5000;
//noinspection JSJQueryEfficiency
$('#iptEnterPromo').on('keyup', function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping($(this).val()), doneTypingInterval);
});
//noinspection JSJQueryEfficiency
$('#iptEnterPromo').on('keydown', function() {
clearTimeout(typingTimer);
});
if ($('#iptDisplayPromo') != null) {
//noinspection JSJQueryEfficiency
$('#iptDisplayPromo').on('keyup', function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping($(this).val()), doneTypingInterval);
});
//noinspection JSJQueryEfficiency
$('#iptDisplayPromo').on('keydown', function() {
clearTimeout(typingTimer);
});
//noinspection JSJQueryEfficiency
$('#iptDisplayPromo').bind('input', function() {
if (document.getElementById("iptPromoCode") != null)
document.getElementById("iptPromoCode").value = $(this).val();
if (document.getElementById("iptPromoCodeSignUp") != null)
document.getElementById("iptPromoCodeSignUp").value = $(this).val();
if (document.getElementById("iptPromoCodeSignIn") != null)
document.getElementById("iptPromoCodeSignIn").value = $(this).val();
document.getElementById("iptEnterPromo").value = $(this).val();
});
}
//noinspection JSJQueryEfficiency
$('#iptEnterPromo').bind('input', function() {
if (document.getElementById("iptPromoCode") != null)
document.getElementById("iptPromoCode").value = $(this).val();
if (document.getElementById("iptPromoCodeSignUp") != null)
document.getElementById("iptPromoCodeSignUp").value = $(this).val();
if (document.getElementById("iptPromoCodeSignIn") != null)
document.getElementById("iptPromoCodeSignIn").value = $(this).val();
if (document.getElementById("iptDisplayPromo") != null)
document.getElementById("iptDisplayPromo").value = $(this).val();
});
function doneTyping(promoCode) {
var costDefault = parseFloat(document.getElementById("iptCostDefault").value);
$.ajax({
method: "GET",
url: ajaxPromoUrl,
data: { "promoCode": promoCode, "costDefault": costDefault, "orderId": orderId }
}).success(function(msg) {
var costPromo = parseFloat(msg);
if (costPromo != 0) {
if (document.getElementById("divViewPromo") != null)
document.getElementById("divViewPromo").innerHTML = '';
document.getElementById("iptCostDiscount").value = costPromo;
} else {
if (document.getElementById("divViewPromo") != null && promoCode != "")
document.getElementById("divViewPromo").innerHTML = '<span style="color: indianred">' + messagePromoError + '</span>';
document.getElementById("iptCostDiscount").value = 0;
}
viewCostTotal(costDefault);
});
}
$(document).ready(function() {
doneTyping($("#iptEnterPromo").val());
});
});
// ------------------------------------------------------------------------------------------------------------
CostTotal = выводит