Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Can now use convertUnit to round to 0 decimal places. #8

Merged
merged 1 commit into from

2 participants

@josher19

Nice library! I found a minor bug where convertUnit does not allow one to round to 0 decimal places. Fixed in this pull request.

Can now use convertUnit to round to 0 decimal places:

geolib.convertUnit('mi', 5000*1000, 0) === 3107

and

geolib.convertUnit('mi', 5000*1000) === 3106.856

while before it was incorrectly being rounded to 4 places instead of 0:

geolib.convertUnit('mi', 5000*1000, 0) === 3106.856

I generally recommend using

arg = (null == arg ? DEFAULT : arg);

instead of

arg = arg || DEFAULT;

for giving default arguments in Javascript because that way you get the default for null and undefined items while keeping "falsy" items such as 0, false, and "".

@josher19 josher19 Can use convertUnit to round to 0 decimal places.
    geolib.convertUnit('mi', 5000*1000, 0) === 3107
and
    geolib.convertUnit('mi', 5000*1000) === 3106.856
while before,
    geolib.convertUnit('mi', 5000*1000, 0) === 3106.856

Generally suggest using 
    arg = (null == arg ? DEFAULT : arg)
instead of
    arg = arg || DEFAULT
for giving default arguments.
0e90fd7
@manuelbieh manuelbieh merged commit 390e9d4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2012
  1. @josher19

    Can use convertUnit to round to 0 decimal places.

    josher19 authored
        geolib.convertUnit('mi', 5000*1000, 0) === 3107
    and
        geolib.convertUnit('mi', 5000*1000) === 3106.856
    while before,
        geolib.convertUnit('mi', 5000*1000, 0) === 3106.856
    
    Generally suggest using 
        arg = (null == arg ? DEFAULT : arg)
    instead of
        arg = arg || DEFAULT
    for giving default arguments.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 2 deletions.
  1. +3 −2 geolib.js
View
5 geolib.js
@@ -510,7 +510,8 @@
* Converts a distance from meters to km, mm, cm, mi, ft, in or yd
*
* @param string Format to be converted in
- * @param float Distance
+ * @param float Distance in meters
+ * @param float Decimal places for rounding (default: 4)
* @return float Converted distance
*/
convertUnit: function(unit, distance, round) {
@@ -527,7 +528,7 @@
}
unit = unit || 'm';
- round = round || 4;
+ round = (null == round ? 4 : round);
switch(unit) {
Something went wrong with that request. Please try again.