public static int formatDouble()

in gflog-core/src/main/java/com/epam/deltix/gflog/core/util/Formatting.java [1396:1427]


    public static int formatDouble(@Nonnegative double value,
                                   final @Nonnegative int precision,
                                   final @Nonnull byte[] array,
                                   @Nonnegative int offset) {
        // Preconditions:
        // assert !Double.isNaN(value) && Long.MIN_VALUE < value && value <= Long.MAX_VALUE;
        // assert precision >= 0 && precision <= 9
        // assert array != 0;
        // assert offset >= 0;

        if (value < 0) {
            value = -value;
            offset = formatByte(MINUS, array, offset);
        }

        final int multiplier = multiplierOfUInt(precision);
        long integer = (long) value;
        int fraction = (int) Math.round((value - integer) * multiplier);

        if (fraction >= multiplier) {
            integer++;
            fraction -= multiplier;
        }

        offset = formatULong(integer, array, offset);

        if (fraction > 0) {
            offset = formatFraction(fraction, precision, array, offset);
        }

        return offset;
    }