Index: /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java	(revision 4540)
+++ /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java	(revision 4541)
@@ -12,4 +12,6 @@
 import static java.lang.Math.toRadians;
 
+import java.math.BigDecimal;
+import java.math.MathContext;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
@@ -28,4 +30,5 @@
 public class LatLon extends Coordinate {
 
+    
     /**
      * Minimum difference in location to not be represented as the same position.
@@ -33,4 +36,5 @@
      */
     public static final double MAX_SERVER_PRECISION = 1e-7;
+    public static final int    MAX_SERVER_DIGITS = 7;
 
     private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00");
@@ -240,5 +244,8 @@
      */
     public static double roundToOsmPrecision(double value) {
-        return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION;
+        double absV = Math.abs(value);
+        int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 
+        return BigDecimal.valueOf(value).round(new MathContext(numOfDigits)).doubleValue();
+        //return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; // Old method, causes rounding errors (see LatLonTest) !
     }
     
Index: /trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java	(revision 4541)
+++ /trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java	(revision 4541)
@@ -0,0 +1,43 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.coor;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * @author Vincent
+ *
+ */
+public class LatLonTest {
+
+    @Test
+    public void roundingTests() {
+        
+        for (double value : new double[]{
+                -180.0, -179.9, -179.6, -179.5, -179.4, -179.1, -179.0, -100.0, -99.9, -10.0, -9.9, -1.0, -0.1,
+                 180.0,  179.9,  179.6,  179.5,  179.4,  179.1,  179.0,  100.0,  99.9,  10.0,  9.9,  1.0,  0.1,
+                 0.12, 0.123, 0.1234, 0.12345, 0.123456, 0.1234567,
+                 1.12, 1.123, 1.1234, 1.12345, 1.123456, 1.1234567,
+                 10.12, 10.123, 10.1234, 10.12345, 10.123456, 10.1234567,
+                 100.12, 100.123, 100.1234, 100.12345, 100.123456, 100.1234567
+                }) {
+            assertEquals(LatLon.roundToOsmPrecision(value), value, 0);
+        }
+        
+        assertEquals(LatLon.roundToOsmPrecision(0.0), 0.0, 0);
+        assertEquals(LatLon.roundToOsmPrecision(-0.0), 0.0, 0);
+        
+        assertEquals(LatLon.roundToOsmPrecision(0.12345678),  0.1234568, 0);
+        assertEquals(LatLon.roundToOsmPrecision(0.123456789), 0.1234568, 0);
+
+        assertEquals(LatLon.roundToOsmPrecision(1.12345678),  1.1234568, 0);
+        assertEquals(LatLon.roundToOsmPrecision(1.123456789), 1.1234568, 0);
+
+        assertEquals(LatLon.roundToOsmPrecision(10.12345678),  10.1234568, 0);
+        assertEquals(LatLon.roundToOsmPrecision(10.123456789), 10.1234568, 0);
+
+        assertEquals(LatLon.roundToOsmPrecision(100.12345678),  100.1234568, 0);
+        assertEquals(LatLon.roundToOsmPrecision(100.123456789), 100.1234568, 0);
+    }
+}
