Class NumberFormatUtil


  • public class NumberFormatUtil
    extends Object
    This class contains methods to format numbers.
    • Method Detail

      • formatFloatFast

        public static int formatFloatFast​(float value,
                                          int maxFractionDigits,
                                          byte[] asciiBuffer)
        Fast variant to format a floating point value to a ASCII-string. The format will fail if the value is greater than Long.MAX_VALUE, smaller or equal to Long.MIN_VALUE, is Float.NaN, infinite or the number of requested fraction digits is greater than MAX_FRACTION_DIGITS. When the number contains more fractional digits than maxFractionDigits the value will be rounded. Rounding is done to the nearest possible value, with the tie breaking rule of rounding away from zero.
        Parameters:
        value - The float value to format
        maxFractionDigits - The maximum number of fraction digits used
        asciiBuffer - The output buffer to write the formatted value to
        Returns:
        The number of bytes used in the buffer or -1 if formatting failed