public static int formatFloatFast(float value, int maxFractionDigits, byte[] asciiBuffer)
    {
        if (Float.isNaN(value) ||
                Float.isInfinite(value) ||
                value > Long.MAX_VALUE ||
                value <= Long.MIN_VALUE ||
                maxFractionDigits > MAX_FRACTION_DIGITS)
        {
            return -1;
        }

        int offset = 0;
        long integerPart = (long) value;

        //handle sign
        if (value < 0)
        {
            asciiBuffer[offset++] = '-';
            integerPart = -integerPart;
        }
        
        //extract fraction part 
        long fractionPart = (long) ((Math.abs((double)value) - integerPart) * POWER_OF_TENS[maxFractionDigits] + 0.5d);
        
        //Check for rounding to next integer
        if (fractionPart >= POWER_OF_TENS[maxFractionDigits]) {
            integerPart++;
            fractionPart -= POWER_OF_TENS[maxFractionDigits];
        }

        //format integer part
        offset = formatPositiveNumber(integerPart, getExponent(integerPart), false, asciiBuffer, offset);
        
        if (fractionPart > 0 && maxFractionDigits > 0)
        {
            asciiBuffer[offset++] = '.';
            offset = formatPositiveNumber(fractionPart, maxFractionDigits - 1, true, asciiBuffer, offset);
        }

        return offset;
    }
@Test
    void testFormatOfRealValues()
    {
        assertEquals(3, NumberFormatUtil.formatFloatFast(0.7f, 5, buffer));
        assertArrayEquals(new byte[]{'0', '.', '7'}, Arrays.copyOfRange(buffer, 0, 3));

        assertEquals(4, NumberFormatUtil.formatFloatFast(-0.7f, 5, buffer));
        assertArrayEquals(new byte[]{'-', '0', '.', '7'}, Arrays.copyOfRange(buffer, 0, 4));

        assertEquals(5, NumberFormatUtil.formatFloatFast(0.003f, 5, buffer));
        assertArrayEquals(new byte[]{'0', '.', '0', '0', '3'}, Arrays.copyOfRange(buffer, 0, 5));

        assertEquals(6, NumberFormatUtil.formatFloatFast(-0.003f, 5, buffer));
        assertArrayEquals(new byte[]{'-', '0', '.', '0', '0', '3'}, 
                          Arrays.copyOfRange(buffer, 0, 6));
    }