无法在JavaScript中转换计算

时间:2017-03-13 02:01:33

标签: javascript html math

我无法将计算转换为JavaScript。任何帮助将不胜感激。以下是我目前所拥有的一个例子。

我很难将其转换为javascript:

(a *(1 + b)^ c)+ d *(((1 + b)^(c) - 1)/ b)

变量

$(document).ready(function() {
  $.ajax({
    type: "POST",
    url: '@Url.Action("FlatType", "Home", new {id = ViewBag.Id})',
    async: true,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    cache: false,
    success: function(data) {
      // Create Table Headers
      let $thead = $('#myColumns'),
          $tr = $('<tr>');

      data.data[0].forEach(col => {
        $tr.append($('<th>').html(col));
      });

      $thead.append($tr);
    }
  });
  $.ajax({
    type: "POST",
    url: '@Url.Action("FlatTypeById", "Home", new {id = ViewBag.Id })',
    async: true,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    cache: false,
    success: function(data) {
      // Create Table Rows
      let $tbody = $('#myData');
      data.data.forEach(row => {
        let $tr = $('<tr>');
        $tr.append(row.map(val => {
          return $('<td>').html(val);
        }));
        $tbody.append($tr);
      });
    }
  });
});

方式

var a = 1250;
var b = 0.03;
var c = 25;
var d = 3234;
var total = 0;

我的getTotal达到120526.48 但据我所知,它应该是102297

再次感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我将公式重写为:

(a * Math.pow((1 + b), c) + d * ((Math.pow((1 + b), c)) - 1) / b)

var aCalculation = function(a, b, c, d) {
  var total = 0;
  total = (a * Math.pow((1 + b), c) + d * ((Math.pow((1 + b), c)) - 1) / b);
  return total;
};

console.log(aCalculation(1250, 0.03, 25, 3234));

Excel同意:

enter image description here