Facility Control

 View Only
  • 1.  Uneven Percentage Calculation

    Posted 07-21-2017 19:23

    Hi Guys

    I am calculating percentage using timers.

    But for some reason my two percentage values do not add up to 100%.

    Is there a way to solve this?

    Iv added a screen grab and the code im using.

    Cheers 



  • 2.  RE: Uneven Percentage Calculation

    Posted 07-24-2017 13:39

    Hi Dennis.
    You need to add rounding to your numbers before turning them into strings. The code as written is using truncation (throwing away everything to the right of the decimal) which means numbers like 5.9 (which should round to 6) will instead be cut-off as 5.

    <button buttontype="push" height="23" left="258" top="386" width="99">
       <task tasktype="ogscript">
    
    var homeposs = "";
    
    /*! block id=1089,1088,1137,1060,1059,1056,1087 !*/
    homeposs =  (Math.round(((params.getValue('0x29', 0) / params.getValue('0x1000', 0)) * 100)) + ".");
    /*! block id=1094,1092,1091,1093,1090 !*/
    params.setValue('Home.Poss', 0, homeposs.substr(0,homeposs.indexOf(".",0)));
    /*!!
     &lt;block id="1089" type="homeposs_Generic Variable_variable" x="1350" y="10" w="243" color="#ee862a" SET="ID:1088"  next="ID:1094" /&gt;
    &lt;block id="1088" type="math_add" x="1077" y="10" VALUE="ID:1137" VAL_1="." w="218" VAL_1_1="" /&gt;
    &lt;block id="1137" type="math_round" x="804" y="10" w="168" VALUE="ID:1060" /&gt;
    &lt;block id="1060" type="math_multiply" x="531" y="10" VALUE="ID:1059" VAL_1="100" w="218" VAL_1_1="" /&gt;
    &lt;block id="1059" type="math_divide" x="283" y="10" VALUE="ID:1056" VAL_1="ID:1087" w="218" VAL_1_1="" /&gt;
    &lt;block id="1056" type="param_Home.Penalty1.Input (0x29)[0]" x="10" y="10" w="243" SET="" /&gt;
    &lt;block id="1087" type="param_Period.Clock (0x1000)[0]" x="10" y="72" w="243" SET="" /&gt;
    &lt;block id="1094" type="param_Home.Poss (Home.Poss)[0]" x="1350" y="144" w="243" SET="ID:1092" /&gt;
    &lt;block id="1092" type="substr" x="1077" y="144" w="243" STRING="ID:1091" start="0" length="ID:1093" /&gt;
    &lt;block id="1091" type="homeposs_Generic Variable_variable" x="804" y="144" w="243" color="#ee862a" SET="" /&gt;
    &lt;block id="1093" type="indexOf" x="804" y="206" w="243" STRING="ID:1090" searchvalue="." start="0" /&gt;
    &lt;block id="1090" type="homeposs_Generic Variable_variable" x="531" y="206" w="243" color="#ee862a" SET="" /&gt;
    !!*/
    /*!!&lt;checksum&gt;033264221fd34b8a7335657c7d561188&lt;/checksum&gt;!!*/</task>
       <task tasktype="ogscript">
    
    var awayposs = "";
    
    /*! block id=1129,1128,1136,1127,1126,1124,1125 !*/
    awayposs =  (Math.round(((params.getValue('0x35', 0) / params.getValue('0x1000', 0)) * 100)) + ".");
    /*! block id=1134,1131,1133,1130,1132 !*/
    params.setValue('Away.Poss', 0, awayposs.substr(0,awayposs.indexOf(".",0)));
    /*!!
     &lt;block id="1129" type="awayposs_Generic Variable_variable" x="1350" y="10" w="243" color="#ee862a" SET="ID:1128"  next="ID:1134" /&gt;
    &lt;block id="1128" type="math_add" x="1077" y="10" VALUE="ID:1136" VAL_1="." w="218" VAL_1_1="" /&gt;
    &lt;block id="1136" type="math_round" x="804" y="10" w="168" VALUE="ID:1127" /&gt;
    &lt;block id="1127" type="math_multiply" x="531" y="10" VALUE="ID:1126" VAL_1="100" w="218" VAL_1_1="" /&gt;
    &lt;block id="1126" type="math_divide" x="283" y="10" VALUE="ID:1124" VAL_1="ID:1125" w="218" VAL_1_1="" /&gt;
    &lt;block id="1124" type="param_Away.Penalty1.Input (0x35)[0]" x="10" y="10" w="243" SET="" /&gt;
    &lt;block id="1125" type="param_Period.Clock (0x1000)[0]" x="10" y="72" w="243" SET="" /&gt;
    &lt;block id="1134" type="param_Away.Poss (Away.Poss)[0]" x="1350" y="144" w="243" SET="ID:1131" /&gt;
    &lt;block id="1131" type="substr" x="1077" y="144" w="243" STRING="ID:1133" start="0" length="ID:1130" /&gt;
    &lt;block id="1133" type="awayposs_Generic Variable_variable" x="804" y="144" w="243" color="#ee862a" SET="" /&gt;
    &lt;block id="1130" type="indexOf" x="804" y="206" w="243" STRING="ID:1132" searchvalue="." start="0" /&gt;
    &lt;block id="1132" type="awayposs_Generic Variable_variable" x="531" y="206" w="243" color="#ee862a" SET="" /&gt;
    !!*/
    /*!!&lt;checksum&gt;ccc9312e86b5e08c78d4e49feca24169&lt;/checksum&gt;!!*/</task>
    </button>
    

    #DashBoard