将BTC jQuery计算器解析为美元



我在javascript/jquery中有这个投资计算器。它根据特定计划计算某人将获得的利润。它被写成与比特币值一起工作,就像这样0.36000000 BTC。我只需要将其解析为3,6格式。

https://pastebin.com/DZvWxEkt

jQuery(function($){
    //Setting calculator
    var percent     = [0.36,0.46,0.52];
    var minMoney    = [0.001,5.001, 10.001];
    var maxMoney    = [5,10,99999999.9999];
    $("#btc_amt").val(minMoney[0]);
    /*calculator*/
    function calc(){
        money = parseFloat($("#btc_amt").val());
        id = -1;
        var length = percent.length;
        var i = 0;
        do {
            if(minMoney[i] <= money && money <= maxMoney[i]){
                id = i;
                i = i + length;
            }
            i++
        }
        while(i < length)
        if(id != -1){
            profitHourly = money / 100 * percent[id];
            profitHourly = profitHourly.toFixed(8);
            profitDaily = profitHourly * 24;
            profitDaily = profitDaily.toFixed(8);
            profitWeekly = profitDaily * 7;
            profitWeekly = profitWeekly.toFixed(8);
            profitMonthly = profitDaily * 30;
            profitMonthly = profitMonthly.toFixed(8);

            if(money < minMoney[id] || isNaN(money) == true){
                $("#profitHourly").text("Error!");
                $("#profitDaily").text("Error!");
                $("#profitWeekly").text("Error!");
                $("#profitMonthly").text("Error!");
                //$("#total_profit").text("Error!");
            } else {
                $("#profitHourly").text(profitHourly + " BTC");
                $("#profitDaily").text(profitDaily + " BTC");
                $("#profitWeekly").text(profitWeekly + " BTC");
                $("#profitMonthly").text(profitMonthly + " BTC");
                //$("#total_profit").text(profitTotal + " BTC");
            }
        } else {
            $("#profitHourly").text("Error!");
            $("#profitDaily").text("Error!");
            $("#profitWeekly").text("Error!");
            $("#profitMonthly").text("Error!");
            //$("#total_profit").text("Error!");
        }
        if(money >= 0.001 && money <= 5 ){
            $('#active-plan').text('0.36% Hourly profit');
            $("#h_id1").prop("checked", true);
        }
        if(money >= 5.001 && money <= 10 ){
            $('#active-plan').text('0.46% Hourly profit');
            $("#h_id2").prop("checked", true);
        }
        if(money >= 10.001 ){
            $('#active-plan').text('0.52% Hourly profit');
            $("#h_id3").prop("checked", true);
        }
    }
    calc();
    if($("#btc_amt").length){
        calc();
    }
    $("#btc_amt").keyup(function(){
        calc();
    });
    $("#h_id1").change(function(){
          if ($(this).is(':checked')){
              $('#btc_amt').val('0.001');
          }
          calc();
      });
      $("#h_id2").change(function(){
          if ($(this).is(':checked')){
              $('#btc_amt').val('5.001');
          }
          calc();
      });
      $("#h_id3").change(function(){
          if ($(this).is(':checked')){
              $('#btc_amt').val('10.001');
          }
          calc();
      });
    var clipboard = new Clipboard('.btn');
    });

让它工作了,谢谢。刚刚更改了toFixed(n)的数量

 $.getJSON( "https://api.coindesk.com/v1/bpi/currentprice/usd.json", 
    function( data) {
    var amountInBtc = 0.005; //convert 0.005 btc to usd
    var exchangeRate = parseInt(data.bpi.USD.rate_float);
    var amount = amountInBtc * exchangeRate;
    console.log(amount);
    });

在这里阅读全文

最新更新