lojix/power_model/src/main/com/thesett/aima/attribute/time/BitHackUtils.java
public static int getCharacterCountDecimal(long integerValue, int scale)
    {
        boolean isNeg = integerValue < 0;

        // Work out how many digits will be needed for the number, adding space for the minus sign, the decimal
        // point and leading zeros if needed.
        int totalDigits = BitHackUtils.getCharacterCountInt64(integerValue);
        int totalLength = totalDigits;

        if (isNeg)
        {
            totalDigits--; // Minus sign already accounted for.
        }

        if (scale > 0)
        {
            totalLength++; // For the decimal point.

            if (scale >= totalDigits)
            {
                // For the leading zeros (+ 1 for the zero before decimal point).
                totalLength += (scale - totalDigits) + 1;
            }
        }
        else
        {
            // Add a zero for each negative point in scale
            totalLength -= scale;
        }

        return totalLength;
    }
public static int getCharacterCountDecimal(long integerValue, int scale)
    {
        boolean isNeg = integerValue < 0;

        // Work out how many digits will be needed for the number, adding space for the minus sign, the decimal
        // point and leading zeros if needed.
        int totalDigits = BitHackUtils.getCharacterCountInt64(integerValue);
        int totalLength = totalDigits;

        if (isNeg)
        {
            totalDigits--; // Minus sign already accounted for.
        }

        if (scale > 0)
        {
            totalLength++; // For the decimal point.

            if (scale >= totalDigits)
            {
                // For the leading zeros (+ 1 for the zero before decimal point).
                totalLength += (scale - totalDigits) + 1;
            }
        }
        else
        {
            // Add a zero for each negative point in scale
            totalLength -= scale;
        }

        return totalLength;
    }
Calculates the number of ASCII characters that will be needed to represent a specified signed decimal number.

@param  integerValue The integer component of the decimal number.
@param  scale        The scale component of the decimal number.

@return The number of ASCII character need to represent a signed decimal number.