User Tools

Site Tools


Sidebar


Site Information


Interactive Maps

Sidebar

wiki:calculator_percent_change

Calculator, Percent Change

Difference: 00.00
Pecent Change: 00.00%
 


pctchange.html
====== Calculator, Percent Change ======
<html>
<head>
   <style type="text/css" media="screen, print, projection">
        body,
        html {
            margin:0;
            padding:0;
            color:#000;
            background:#fff;
        }
        #wrap {
            width:1000px;
            margin:0 auto;
            background:#fff;
        }
        #main {
            float:left;
            // width:480px;
            padding:0 10px;
            background:#fff;
        }
   </style>
 
   <script type="text/javascript">
 
     function fnCalc() {
        var nBeg = frmCalcRate.numBeg.value;
        // remove all commas
        nBeg = parseFloat(nBeg.replace(/,/g,""));
 
        var nEnd = frmCalcRate.numEnd.value;
        // remove all commas
        nEnd = parseFloat(nEnd.replace(/,/g,""));
 
       // alert("nBeg:" + nBeg + " -- Math:" + (nBeg * 2));
       if (0.0 == nBeg) {
         alert("Population cannot be zero.");
       } else if (0.0 == nEnd) {
         alert("Crimes cannot be zero.");
       } else {
         var nDiff = nEnd - nBeg;
         nDiff = nDiff.toFixed(2);
 
         var nChg = (nDiff / nBeg) * 100.00;
         nChg = nChg.toFixed(2);
 
         var diffHtml = document.getElementById("numDiff");
         diffHtml.innerHTML = nDiff.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
         var rateHtml = document.getElementById("perChg");
         rateHtml.innerHTML = nChg.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");;
       }
       return false;
     }
 
   </script>
 
</head>
<body>
<div id="wrap">
   <div id="main">
        <form name="CalcRateForm" id="frmCalcRate" action="">
            <table>
                <tr>
                    <td><label for="numBeg"><strong>Begining Value:</strong></label></td>
                    <td><input type="text" id="numBeg"></td>
                </tr>
 
                <tr>
                    <td><label for="numEnd"><strong>Ending Value:</strong></label></td>
                    <td colspan="2"><input type="text" id="numEnd"></td>
                </tr>
 
                <tr>
                    <td><strong>Difference:</strong></td>
                    <td><span id="numDiff">00.00</span></td>
                </tr>
 
                <tr>
                    <td><strong>Pecent Change:</strong></td>
                    <td><span id="perChg">00.00</span>%</td>
                </tr>
 
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="2"><input type="submit" value="Submit" onclick="return fnCalc();"></td>
                </tr>
            </table>
        </form>
   </div>
</div>
</body>
</html>
wiki/calculator_percent_change.txt · Last modified: 2016/10/11 05:59 by terrill