code: public static int toDecimalDigits(double v,
                                        char[] digits, int offset, int maxDigits,
                                        int maxFractDigits, int roundMode)
      {
          // NOTE: The value 144115188075855872 is converted to
          // 144115188075855870, which is as correct as possible. Java's
          // Double.toString method doesn't round off the last digit.
  
          long bits = Double.doubleToLongBits(v);
          long f = bits & 0xfffffffffffffL;
          int e = (int)((bits >> 52) & 0x7ff);
          if (e != 0) {
              // Normalized number.
              return toDecimalDigits(f + 0x10000000000000L, e - 1022, 53,
                                     digits, offset, maxDigits, maxFractDigits,
                                     roundMode);
          }
          else {
              // Denormalized number.
              return toDecimalDigits(f, -1023, 52, digits, offset,
                                     maxDigits, maxFractDigits, roundMode);
          }
      }
docs: Produces decimal digits for non-zero, finite floating point values.
  The sign of the value is discarded. Passing in Infinity or NaN produces
  invalid digits. The maximum number of decimal digits that this
  function will likely produce is 18.
  
  @param v value
  @param digits buffer to receive decimal digits
  @param offset offset into digit buffer
  @param maxDigits maximum number of digits to produce
  @param maxFractDigits maximum number of fractional digits to produce
  @param roundMode i.e. ROUND_HALF_UP
  @return Upper 16 bits: decimal point offset; lower 16 bits: number of
  digits produced