javascript - Can't use variable in parentheses only direct input to convert dms to dd -


i know considered duplicate question, in fairness have been researching last week trying everyone's methods ending same way.

basically work input value directly, when try reference variable gives "nan" response.

for example if wanted call function "locationformatter.dmstodecimal(myvar);" return "nan".

updated answer, snippet below.

 // set `longcombined` array ,    // preserve individual item `type` ; e.g.; `number` , `string`    var longcombined = [81, 36.96, 0, 'w'];      // set `locationformatter` `object`    var locationformatter = {};      locationformatter.north = 'n';    locationformatter.south = 's';    locationformatter.east = 'e';    locationformatter.west = 'w';      locationformatter.roundtodecimal = function (inputnum, numpoints) {        var multiplier = math.pow(10, numpoints);        return math.round(inputnum * multiplier) / multiplier;    };      locationformatter.dmstodecimal = function (degrees, minutes, seconds, hemisphere) {        var ddval = degrees + minutes / 60 + seconds / 3600;        ddval = (hemisphere == locationformatter.south || hemisphere == locationformatter.west) ? ddval * -1 : ddval;        return locationformatter.roundtodecimal(ddval, 5);    };    document.getelementbyid("demo1").innerhtml = locationformatter.dmstodecimal(81, 36.96, 0, 'w');      // call `locationformatter.dmstodecimal` utilizing `.apply()`,    // set `locationformatter` `this` , pass `longcombined` argument `locationformatter.dmstodecimal`    document.getelementbyid("demo2").innerhtml = locationformatter.dmstodecimal.apply(locationformatter, longcombined);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>this 1 using varible</p>  <p id="demo1"></p>  <p>this using direct input</p>  <p id="demo2"></p>  <script>        </script>

  // set `longcombined` array ,   // preserve individual item `type` ; e.g.; `number` , `string`   var longcombined = [81, 36.96, 0, 'w'];    // set `locationformatter` `object`   var locationformatter = {};    locationformatter.north = 'n';   locationformatter.south = 's';   locationformatter.east = 'e';   locationformatter.west = 'w';    locationformatter.roundtodecimal = function (inputnum, numpoints) {       var multiplier = math.pow(10, numpoints);       return math.round(inputnum * multiplier) / multiplier;   };    locationformatter.dmstodecimal = function (degrees, minutes, seconds, hemisphere) {       var ddval = degrees + minutes / 60 + seconds / 3600;       ddval = (hemisphere == locationformatter.south || hemisphere == locationformatter.west) ? ddval * -1 : ddval;       return locationformatter.roundtodecimal(ddval, 5);   };   document.getelementbyid("demo1").innerhtml = locationformatter.dmstodecimal(81, 36.96, 0, 'w');    // call `locationformatter.dmstodecimal` utilizing `.apply()`,   // set `locationformatter` `this` , pass `longcombined` argument `locationformatter.dmstodecimal`   document.getelementbyid("demo2").innerhtml = locationformatter.dmstodecimal.apply(locationformatter, longcombined); 

jsfiddle https://jsfiddle.net/3h7z1kv7/2/


Comments

Popular posts from this blog

node.js - Using Node without global install -

java - Null response to php query in android, even though php works properly -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -