Skip to content

LngLat.fmtCoordinate returns wrong values for negative arguments #2

@pqyptixa

Description

@pqyptixa

LngLat.fmtCoordinate returns wrong values when the "value" parameter is negative (for western/southern longitudes/latitudes, respectively).
Here's a patch:

--- a/haxemap/core/LngLat.hx
+++ b/haxemap/core/LngLat.hx
@@ -55,9 +55,10 @@ class LngLat
     //convert coordinate to string (format %.6f)
     static public function fmtCoordinate(value:Float) : String
     {
-       var valuef:Float = Math.floor(value);
-       var f:Float = value - valuef;
-       var s:String = Std.string(valuef) + ".";
+       var tmp_value:Float = (value > 0 ? value : -value);
+       var valuef:Float = Math.floor(tmp_value);
+       var f:Float = tmp_value - valuef;
+       var s:String = (value > 0 ? "" : "-") + Std.string(valuef) + ".";
        for (i in 0...6)
        {
            f *= 10.0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions