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 testFormatOfIntegerValues()
    {
        assertEquals(2, NumberFormatUtil.formatFloatFast(51, 5, buffer));
        assertArrayEquals(new byte[]{'5', '1'}, Arrays.copyOfRange(buffer, 0, 2));

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

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

        assertEquals(19, NumberFormatUtil.formatFloatFast(Long.MAX_VALUE, 5, buffer));
        assertArrayEquals(new byte[]{'9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5', 
                                     '4', '7', '7', '5', '8', '0', '7'}, 
                          Arrays.copyOfRange(buffer, 0, 19));

        //Note: Integer.MAX_VALUE would be 2147483647, but when converting to float, we have 
        //      precision errors. NumberFormat.getIntegerInstance() does also print 2147483648 for 
        //      such a float
        assertEquals(10, NumberFormatUtil.formatFloatFast(Integer.MAX_VALUE, 5, buffer));
        assertArrayEquals(new byte[]{'2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 
                          Arrays.copyOfRange(buffer, 0, 10));

        assertEquals(11, NumberFormatUtil.formatFloatFast(Integer.MIN_VALUE, 5, buffer));
        assertArrayEquals(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 
                          Arrays.copyOfRange(buffer, 0, 11));
    }