2017-10-24 6 views
-1

두 개의 함수가 일치하고 합계가 제대로 작동합니다. 함수 총 프로젝트 일치를 두 번째 함수 곱하기 100 곱하기 첫 번째 함수를 나누고 싶습니다. 마지막 함수가 작동하지 않습니다!두 개의 입력을 나누고 100을 곱하십시오.

여기에 지금까지 내 코드입니다 :

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

오류에 대한 자세한 내용을 제공해 주시겠습니까? 그리고 정확히 당신은 무엇을 말하고 있습니까? 게시 된 코드의 두 번째 기능이 무엇인지는 분명하지 않습니다. 관련 코드를 게시하기 전에 질문을 추가하십시오. – SaschaM78

+0

@ SaschaM78, ​​답장을 보내 주셔서 감사합니다. 난 그냥 matchProribution의 값을 totalProjectCost의 값으로 나누고 100을 곱하고 싶다. 고마워! –

+0

코드의 게시 된 부분에 나는 당신이 100을 곱하는 것을 볼 수 없습니다 (당신이 알고있는 것처럼'var totalProjectMatch = (matchContribution()/totalProjectCost() * 100);) 될 것입니다. 'console.log()'를 사용하여 _matchContribution() _ 및 _totalProjectCost() _ 값을 얻으려고 했습니까? – SaschaM78

답변

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); 
     } 
    }); 

내가 문제를 해결! 고마워요! 희망은 다른 사람들을 돕습니다.