Currency Convertor.

POSTED BY rameko April 22, 2020
    

    

D&D 5e coin converter

Instructions
Use this tool to convert lower value coins to higher value coins. Additionally, evenly split coins between team members.
Exchange Rate
Coin cp sp ep gp pp
Copper (cp) 1 1/10 1/50 1/100 1/1,000
Silver (sp) 10 1 1/5 1/10 1/100
Electrum (ep) 50 5 1 1/2 1/20
Gold (gp) 100 10 2 1 1/10
Platinum (pp) 1,000 100 20 10 1
<script type="text/javascript">
    function toInteger(number, defaultValue) {
        return !isNaN(number) ? parseInt(number) : defaultValue;
    }

    function toCoinStr(results) {
        var str = "";
        for (var key in results) {
            if (results[key] > 0) {
                str = str.concat(results[key] + key + " ");
            }
        }

        //No coins at all
        if (str.length == 0) {
            str = "No coins ";
        }
        return str;
    }

    function calculate() {
        //1. Get the coin values from the form
        var coins = {
            cp: document.getElementById("cp").value,
            sp: document.getElementById("sp").value,
            ep: document.getElementById("ep").value,
            gp: document.getElementById("gp").value,
            pp: document.getElementById("pp").value
        }   
        var partySize = toInteger(document.getElementById("partySize").value, -1);
        var coinOpts = document.getElementById("csgCoins").checked ? ["cp", "sp", "gp"] : [];

        var result = "";
        if (partySize > -1) {
            var results = ExchangeRate.teamSplit(partySize, coins, coinOpts);
            var strResults = {};
            for (var i=0; i<results.length; i++) {
                var coinStr = toCoinStr(results[i]);
                if (strResults.hasOwnProperty(coinStr)) {
                    strResults[coinStr] += 1;
                } else {
                    strResults[coinStr] = 1;
                }
            }

            result = "<ul>"
            for (var key in strResults) {
                result = result.concat("<li>", "(", strResults[key], ") ", key, "</li>");
            }
            result = result.concat("</ul>");
        } else {
            //2. Get the optimal results
            var results = ExchangeRate.optimalExchange(coins, coinOpts);

            //3. Create a human-readable string showcasing the results
            result = result.concat(toCoinStr(results));
        }

        //Unhide the result
        var resultDiv = document.getElementById("result");
        resultDiv.classList.remove("invisible");

        var placeholder = document.getElementById("placeholder");
        placeholder.innerHTML = result;
        return false;
    }
</script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>