Помогите уменьшить значение в скрипте для виджета

Serjio

Проверенные
Сообщения
546
Реакции
315
Баллы
11,065
Если возможно конечно....
Это онлайн - счетчик ,в котором число равно триллиону. Цифры очень большие. Возможно ли их как нибудь уменьшить? В боковом виджете цифра съезжает на следующую строку. Не красиво смотрится.
Спасибо.

Код:
<h1><span id="debt-clock">&nbsp;</span></h1>
<script type="text/javascript">
<!--
Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };

function calculateDebt(startYear,startMonth,startDay,baseDebt,perSecondDebt,yearPop,monthPop,dayPop,basePop,perSecondPop)
{
//We pass start date (year, month, day), the base value, with the increase per second
// then we figure the difference between days and multiply and add the base:

var one_day_m=1000*60*60*24;  //Get 1 day in milliseconds
var one_day=60*60*24;  //Get 1 day in seconds
var one_sec=1000;  // 1 second in milliseconds
var one_tenthsec=100;  // 1 10th second in milliseconds
var one_fifthsec=200;  // 1 5th second in milliseconds
var one_halfsec=500;  // 0.5 second in milliseconds

//theTime=setTimeout('calculateDebt(2011,5,30,10000000,41234)',one_tenthsec);   
theTime=setTimeout('calculateDebt(2018,12,12,21836655970708.04,31798.53,2011,06,06,311496761,0.076923076923077)',one_tenthsec) ;

//The Date we are starting from in Javascript format based on parameters passed
var startdate = new Date(startYear, startMonth-1, startDay); //  Year/Month/Day - Month is 0-11 in JavaScript
var startPopdate = new Date(yearPop, monthPop-1, dayPop); //  Year/Month/Day - Month is 0-11 in JavaScript


currentUnfundedDebt= 1.14039E+14;
currentUnfundedDebtPerTenth = (168061.9)/10;

currentUnfundedSSDebt= 15100000000000.00;
currentUnfundedSSDebtPerTenth = (38333.21)/10;
currentUnfundedMediCareDebt= 79000000000000.00;
currentUnfundedMediCareDebtPerTenth = (98764.67)/10;
currentUnfundedDrugDebt= 19939000000000.00;
currentUnfundedDrugDebtPerTenth = (18456.11)/10;
currentUnfundedObamaCareDebt= 9200000000000.00;
currentUnfundedObamaCareDebtPerTenth = (7123.21)/10;
currentUnfundedOtherDebt= 0.00;
currentUnfundedDebtOtherPerTenth = (0)/10;

perTenthDebt = perSecondDebt/10;
today=new Date();
elapsedSeconds=Math.ceil((today.getTime()-startdate.getTime())/1000);  //Seconds since start
elapsedTenths=Math.ceil((today.getTime()-startdate.getTime())/100);  //10ths of a second since start
//currentDebt=Math.ceil((elapsedTenths*perTenthDebt)+baseDebt);
currentDebt=(elapsedTenths*perTenthDebt)+baseDebt;

//currentUnfundedDebt = currentUnfundedDebt + (elapsedTenths*currentUnfundedDebtPerTenth);
currentUnfundedSSDebt= currentUnfundedSSDebt + (elapsedTenths*currentUnfundedSSDebtPerTenth);
currentUnfundedMediCareDebt= currentUnfundedMediCareDebt + (elapsedTenths*currentUnfundedMediCareDebtPerTenth);
currentUnfundedDrugDebt= currentUnfundedDrugDebt + (elapsedTenths*currentUnfundedDrugDebtPerTenth);
currentUnfundedObamaCareDebt= currentUnfundedObamaCareDebt + (elapsedTenths*currentUnfundedObamaCareDebtPerTenth);
currentUnfundedOtherDebt= currentUnfundedOtherDebt + (elapsedTenths*currentUnfundedDebtOtherPerTenth);
currentUnfundedDebt = currentUnfundedSSDebt+currentUnfundedMediCareDebt+currentUnfundedDrugDebt+currentUnfundedObamaCareDebt+currentUnfundedOtherDebt;



perTenthPop = perSecondPop/10;
elapsedSeconds=Math.ceil((today.getTime()-startPopdate.getTime())/1000);  //Seconds since start
elapsedTenths=Math.ceil((today.getTime()-startPopdate.getTime())/100);  //10ths of a second since start
currentPop=Math.ceil((elapsedTenths*perTenthPop)+basePop);

currentPersonDebt = currentDebt/currentPop;
currentHouseholdDebt = (currentPersonDebt * 2.59);

currentUnfundedPersonDebt = currentUnfundedDebt/currentPop;
currentUnfHouseholdDebt = currentUnfundedPersonDebt * 2.59;

currentDebtString=currentDebt.formatMoney(2, '.', ',');

currentUnfundedDebtString = currentUnfundedDebt.formatMoney(2, '.', ',');
currentPopString = currentPop.formatMoney(0, '.', ',');
currentPersonDebtString = currentPersonDebt.formatMoney(2, '.', ',');
currentHouseholdDebtString = currentHouseholdDebt.formatMoney(2, '.', ',');
currentUnfundedPersonDebtString = currentUnfundedPersonDebt.formatMoney(2, '.', ',');
currentUnfHouseholdDebtString = currentUnfHouseholdDebt.formatMoney(2, '.', ',');
currentUnfundedSSDebtString = currentUnfundedSSDebt.formatMoney(2, '.', ',');
currentUnfundedMediCareDebtString = currentUnfundedMediCareDebt.formatMoney(2, '.', ',');
currentUnfundedDrugDebtString = currentUnfundedDrugDebt.formatMoney(2, '.', ',');
currentUnfundedObamaCareDebtString = currentUnfundedObamaCareDebt.formatMoney(2, '.', ',');
currentUnfundedOtherDebtString = currentUnfundedOtherDebt.formatMoney(2, '.', ',');



  document.getElementById("debt-clock").firstChild.nodeValue = "$"+currentDebtString;
  document.getElementById("debt-clock-per-person").firstChild.nodeValue = "$"+currentPersonDebtString;
  document.getElementById("debt-clock-per-household").firstChild.nodeValue = "$"+currentHouseholdDebtString;
  document.getElementById("pop-clock").firstChild.nodeValue = currentPopString;
  document.getElementById("unfund-debt-clock").firstChild.nodeValue = "$"+currentUnfundedDebtString;
  document.getElementById("unfund-debt-clock-per-person").firstChild.nodeValue = "$"+currentUnfundedPersonDebtString;
  document.getElementById("unfund-debt-clock-per-household").firstChild.nodeValue = "$"+currentUnfHouseholdDebtString;
  document.getElementById("ss-debt-clock").firstChild.nodeValue = "$"+currentUnfundedSSDebtString;
  document.getElementById("drug-debt-clock").firstChild.nodeValue = "$"+currentUnfundedDrugDebtString;
  document.getElementById("medicare-debt-clock").firstChild.nodeValue = "$"+currentUnfundedMediCareDebtString;
  document.getElementById("obamacare-debt-clock").firstChild.nodeValue = "$"+currentUnfundedObamaCareDebtString;
//-->
}


calculateDebt(2018,12,12,21836655970708.04,31798.53,2011,06,06,311496761,0.076923076923077) ;

</script>
 
Современный облачный хостинг провайдер | Aéza
Назад
Сверху Снизу