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 testRoundingUp()
    {
        assertEquals(1, NumberFormatUtil.formatFloatFast(0.999999f, 5, buffer));
        assertArrayEquals(new byte[]{'1'}, Arrays.copyOfRange(buffer, 0, 1));
        
        assertEquals(4, NumberFormatUtil.formatFloatFast(0.125f, 2, buffer));
        assertArrayEquals(new byte[]{'0','.','1','3'}, Arrays.copyOfRange(buffer, 0, 4));
        
        assertEquals(2, NumberFormatUtil.formatFloatFast(-0.999999f, 5, buffer));
        assertArrayEquals(new byte[]{'-','1'}, Arrays.copyOfRange(buffer, 0, 2));
    }