计算后以NaN形式返回的数字

时间:2018-02-14 03:24:23

标签: javascript numbers coordinates google-places-api nan

我有这段代码:

  ...

  console.log(place.geometry.location.lat() + " lrdrdr " + place.geometry.location.lng());
  var lat = place.geometry.location.lat();
  var lon = place.geometry.location.lng();

  write_points(lat, lon, const_lat, const_lon);
}

function write_points(starting_lat, starting_lon, constant_lat, constant_lon) {
  var counter = 1;
  for (var i = 1; i < 6; i++) {
    var starting_lon_var = starting_lon + constant_lon * (i * Math.random());
    console.log(starting_lat + " lahdeedah " + starting_lon_var);

    ...

这是控制台输出:

42.247865 lrdrdr -71.17272600000001
42.247865 lahdeedah NaN

为什么lrdrdr-71.17272600000001)之后的值在被调用的write_points函数中变为NaN。我将其作为参数(starting_lon)传递,并通过此starting_lon + constant_lon * (i * Math.random())计算,然后在输出时,由于某种原因它会给出NaN

1 个答案:

答案 0 :(得分:0)

检查所有变量的另一个案例 - const_lon被创建为NaN,因为其争议涉及另一个变量。