docs: public static double roundMagic(double d) {
  
          // this function rounds numbers in a good way but slow:
          // - special handling for numbers around 0
          // - only numbers <= +/-1000000000000
          // - convert to a string
          // - check the last 4 characters:
          // '000x' becomes '0000'
          // '999x' becomes '999999' (this is rounded automatically)
          if ((d < 0.0000000000001) && (d > -0.0000000000001)) {
              return 0.0;
          }
  
          if ((d > 1000000000000.) || (d < -1000000000000.)) {
              return d;
          }
  
          StringBuffer sb = new StringBuffer();
  
          sb.append(d);
  
          int len = sb.length();
  
          if (len < 16) {
              return d;
          }
  
          char cx = sb.charAt(len - 1);
          char c1 = sb.charAt(len - 2);
          char c2 = sb.charAt(len - 3);
          char c3 = sb.charAt(len - 4);
  
          if ((c1 == '0') && (c2 == '0') && (c3 == '0') && (cx != '.')) {
              sb.setCharAt(len - 1, '0');
          } else if ((c1 == '9') && (c2 == '9') && (c3 == '9') && (cx != '.')) {
              sb.setCharAt(len - 1, '9');
              sb.append('9');
              sb.append('9');
          }
  
          return Double.valueOf(sb.toString()).doubleValue();
      }