Example #1
0
 /**
  * Appends the decimal representation of the specified <code>long</code> argument.
  *
  * @param l the <code>long</code> to format.
  * @return <code>this</code>
  */
 public final TextBuilder append(long l) {
   if (l <= 0) {
     if (l == 0) return append("0");
     if (l == Long.MIN_VALUE) // Negation would overflow.
     return append("-9223372036854775808");
     append('-');
     l = -l;
   }
   if (l <= Integer.MAX_VALUE) return append((int) l);
   append(l / 1000000000);
   int i = (int) (l % 1000000000);
   int digits = MathLib.digitLength(i);
   append("000000000", 0, 9 - digits);
   return append(i);
 }
Example #2
0
 /**
  * Appends the decimal representation of the specified <code>int</code> argument.
  *
  * @param i the <code>int</code> to format.
  * @return <code>this</code>
  */
 public final TextBuilder append(int i) {
   if (i <= 0) {
     if (i == 0) return append("0");
     if (i == Integer.MIN_VALUE) // Negation would overflow.
     return append("-2147483648");
     append('-');
     i = -i;
   }
   int digits = MathLib.digitLength(i);
   if (_capacity < _length + digits) increaseCapacity();
   _length += digits;
   for (int index = _length - 1; ; index--) {
     int j = i / 10;
     _high[index >> B1][index & M1] = (char) ('0' + i - (j * 10));
     if (j == 0) return this;
     i = j;
   }
 }
Example #3
0
 private final void appendFraction(long l, int digits, boolean showZero) {
   append('.');
   if (l == 0)
     if (showZero)
       for (int i = 0; i < digits; i++) {
         append('0');
       }
     else append('0');
   else { // l is different from zero.
     int length = MathLib.digitLength(l);
     for (int j = length; j < digits; j++) {
       append('0'); // Add leading zeros.
     }
     if (!showZero)
       while (l % 10 == 0) {
         l /= 10; // Remove trailing zeros.
       }
     append(l);
   }
 }