Revision: 5303
          http://sourceforge.net/p/jump-pilot/code/5303
Author:   edso
Date:     2016-12-30 00:45:46 +0000 (Fri, 30 Dec 2016)
Log Message:
-----------
added utility function

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/util/StringUtil.java

Modified: core/trunk/src/com/vividsolutions/jump/util/StringUtil.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/StringUtil.java 2016-12-29 
22:27:57 UTC (rev 5302)
+++ core/trunk/src/com/vividsolutions/jump/util/StringUtil.java 2016-12-30 
00:45:46 UTC (rev 5303)
@@ -373,4 +373,28 @@
 
         return buf.toString();
     }
+
+    /**
+     * format Doubles to String representation, cutting zeroes from the 
decimal end
+     * eg. 1234.000 -> "1234", 1234.5600 -> "1234.56"
+     * @param d
+     * @return string
+     */
+    public static String toString(double d) {
+      if (d == (long) d)
+        return String.format("%d", (long) d);
+      else {
+        // detect number of decimal digits (until there are only zeroes)
+        int i = 1;
+        for (; i <= 12; i++) {
+          double factor = (double) Math.pow(10, i);
+          double temp = ((long) (d * factor)) / factor;
+          System.out.println(temp);
+          if (temp == d)
+            break;
+        }
+        System.out.println("orig:" + d);
+        return String.format("%." + i + "f", d);
+      }
+    }
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to