如何将以下代码的货币面额转换为打字稿

时间:2018-05-15 11:02:23

标签: jquery typescript

请帮我把逻辑提取到打字稿中。我是Js环境的新手。

这是html代码。

<input type="text" id="amt"/><input type="button" value="change" id="btn"/>

<br/>

twothousand: <span></span><br/>
fivehundred: <span></span><br/>
hundred: <span></span><br/>




$("#btn").click(function() {
        makeChange($("#amt").val());
    });

    function makeChange(total) {
        var twothousand, fivehundred, hundred;
        var changeArray = [twothousand,fivehundred,hundred];
        var amtArray = [2000, 500, 100];

        $("span").each(function(i) {
            var currentText = $(this).text();
            //if (total / amtArray[i] != 0) {
                //Set the span
                $(this).text(currentText + parseInt(total / amtArray[i]));
                //Get the new total
                total = total % amtArray[i];
            //}
        });
    }

如果有人为此问题发布解决方案,那将非常有帮助。

1 个答案:

答案 0 :(得分:1)

checkDenomination(total) {
        for (let i = 0; i < this.amtArray.length; i++) {
            this.resultArray.push(Math.floor(total / this.amtArray[i]));
            // Get the new total
            total = total % this.amtArray[i];
        }
        this.cal_twothousands_notes = this.resultArray[0];
        this.cal_fivehundred_notes = this.resultArray[1];
        this.cal_hundred_notes = this.resultArray[2];

        console.log('calculated amt : ' + '100 : ' +
            this.cal_hundred_notes + '   500 :  ' +
            this.cal_fivehundred_notes + '  2000 :  ' +
            this.cal_twothousands_notes);


    }