Skip to content

Commit

Permalink
Revert "Update L.Util.formatNum rounding" (Leaflet#6670)
Browse files Browse the repository at this point in the history
* Revert "Update L.Util.formatNum rounding (Leaflet#6587)"

This reverts commit cd096d7.

* revert docs changes
  • Loading branch information
cherniavskii authored and Schleuse committed Dec 3, 2019
1 parent 0c435c7 commit 29e29ea
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
3 changes: 0 additions & 3 deletions spec/suites/core/UtilSpec.js
Expand Up @@ -86,9 +86,6 @@ describe('Util', function () {
expect(L.Util.formatNum(13.12325555, 3)).to.eql(13.123);
expect(L.Util.formatNum(13.12325555)).to.eql(13.123256);
expect(L.Util.formatNum(13.12325555, 0)).to.eql(13);
expect(L.Util.formatNum(1.005, 2)).to.eql(1.01);
expect(L.Util.formatNum(1.555, 2)).to.eql(1.56);
expect(L.Util.formatNum(-1.4837191022531273, 18)).to.eql(-1.4837191022531273);
});
});

Expand Down
6 changes: 0 additions & 6 deletions spec/suites/layer/GeoJSONSpec.js
Expand Up @@ -80,12 +80,6 @@ describe("L.Marker#toGeoJSON", function () {
type: 'Point',
coordinates: [20.123, 10.123, 30.123]
});

marker = new L.Marker({lng: -1.4837191022531273, lat: 43.49222084042808});
expect(marker.toGeoJSON(18).geometry).to.eql({
type: 'Point',
coordinates: [-1.4837191022531273, 43.49222084042808]
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/core/Util.js
Expand Up @@ -114,8 +114,8 @@ export function falseFn() { return false; }
// @function formatNum(num: Number, digits?: Number): Number
// Returns the number `num` rounded to `digits` decimals, or to 6 decimals by default.
export function formatNum(num, digits) {
digits = (digits === undefined ? 6 : digits);
return +(Math.round(num + ('e+' + digits)) + ('e-' + digits));
var pow = Math.pow(10, (digits === undefined ? 6 : digits));
return Math.round(num * pow) / pow;
}

// @function trim(str: String): String
Expand Down

0 comments on commit 29e29ea

Please sign in to comment.