2017-10-24 5 views
-1

Ich habe die beiden Funktionen übereinstimmen und und insgesamt funktioniert einwandfrei. Ich möchte die Funktion Gesamt-Projekt übereinstimmen, um die erste Funktion über die zweite Funktion multiplizieren multipliziert mal 100. Die letzte Funktion funktioniert nicht!Teilen Sie zwei Eingänge und multiplizieren 100

Hier ist mein Code so weit:

matchContribution.subscribe(function (newValue) { 
      if (newValue != undefined && newValue != '') { 
      matchContribution(formatInt(newValue)); 


     var dataValue = Number(matchContribution().replace(/\,/g, '')); 

     if (dataValue > 999999999999.99 || dataValue < 0) { 
      matchContribution(''); 
     } 

     if (loading == false) { 
      sendCommand('SAVE'); 
     } 
     } 

    }); 

    var totalProjectCost = ko.computed(function() { 
     var total = 0; 
     var hasUserInput = false; 
     if (grantRequest() != '' && grantRequest() != undefined) { 
     hasUserInput = true; 
     total = total + Number(String(grantRequest()).replace(/\,/g, '')); 
     } 

     if (matchContribution() != '' && matchContribution() != undefined) { 
     hasUserInput = true; 
     total = total + Number(String(matchContribution()).replace(/\,/g, '')); 
     } 



     if (total == 0) { 
     if (!hasUserInput) 
      return ''; 
     else 
      return formatInt('0'); 
     } 
     else { 
     if (loading == false) { 
      sendCommand('SAVE'); 
     } 
     return formatInt(total); 
     } 
    }); 

    var totalProjectMatch = matchContribution()/totalProjectCost(); 
    if(totalProjectMatch>=0) 
     totalProjectMatch = Math.floor(totalProjectMatch); 
    else 
     totalProjectMatch = Math.ceil(totalProjectMatch); 
+0

Könnten Sie mehr Informationen über den Fehler geben? Und was genau meinen Sie? Es ist unklar, was die zweite Funktion im gebuchten Code wäre. Und bitte fügen Sie Ihre Frage hinzu, bevor Sie einen relevanten Code veröffentlichen. – SaschaM78

+0

@ SaschaM78, ​​danke für deine Antwort. Ich möchte nur den Wert von matchContribution über den Wert von totalProjectCost teilen und mit 100 multiplizieren. Danke! –

+0

Im angegebenen Teil des Codes kann ich nicht sehen, wo Sie mit 100 multiplizieren (das wäre 'var totalProjectMatch = (matchContribution()/totalProjectCost() * 100);' wie Sie wahrscheinlich am ehesten wissen). Haben Sie versucht, die Werte von _matchContribution() _ und _totalProjectCost() _ mit 'console.log()' zu bekommen? – SaschaM78

Antwort

0
var totalProjectMatch = ko.computed(function() { 
     var total = 0; 
     var hasUserInput = false; 
     if ((grantRequest() != '' && grantRequest() != undefined) && (matchContribution() != '' && matchContribution() != undefined) && (totalProjectCost() != '' && totalProjectCost() != undefined)) { 
     hasUserInput = true; 
     total = Number(String(matchContribution()).replace(/\,/g, ''))/Number(String(totalProjectCost()).replace(/\,/g, '')); 
     total = total * 100; 
     } 


     if (total == 0) { 
     if (!hasUserInput) 
      return ''; 
     else 
      return formatInt('0'); 
     } 
     else { 
     if (loading == false) { 
      sendCommand('SAVE'); 
     } 
     return formatNumber(total); 
     } 
    }); 

ich das Problem gelöst! Danke vielmals! Hoffe das hilft anderen Menschen.

Verwandte Themen