Package org.apache.pdfbox.util
Class NumberFormatUtil
java.lang.Object
org.apache.pdfbox.util.NumberFormatUtil
This class contains methods to format numbers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intMaximum number of fraction digits supported by the format methodsprivate static final long[]Contains the power of ten values for fast lookup in the format methodsprivate static final int[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intformatFloatFast(float value, int maxFractionDigits, byte[] asciiBuffer) Fast variant to format a floating point value to a ASCII-string.private static intformatPositiveNumber(long number, int exp, boolean omitTrailingZeros, byte[] asciiBuffer, int startOffset) Formats a positive integer number starting with the digit at10^exp.private static intgetExponent(long number) Returns the highest exponent of 10 where10^exp < numberfor numbers > 0
-
Field Details
-
MAX_FRACTION_DIGITS
private static final int MAX_FRACTION_DIGITSMaximum number of fraction digits supported by the format methods- See Also:
-
POWER_OF_TENS
private static final long[] POWER_OF_TENSContains the power of ten values for fast lookup in the format methods -
POWER_OF_TENS_INT
private static final int[] POWER_OF_TENS_INT
-
-
Constructor Details
-
NumberFormatUtil
private NumberFormatUtil()
-
-
Method Details
-
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 thanLong.MAX_VALUE, smaller or equal toLong.MIN_VALUE, isFloat.NaN, infinite or the number of requested fraction digits is greater thanMAX_FRACTION_DIGITS. When the number contains more fractional digits thanmaxFractionDigitsthe 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 formatmaxFractionDigits- The maximum number of fraction digits usedasciiBuffer- The output buffer to write the formatted value to- Returns:
- The number of bytes used in the buffer or
-1if formatting failed
-
formatPositiveNumber
private static int formatPositiveNumber(long number, int exp, boolean omitTrailingZeros, byte[] asciiBuffer, int startOffset) Formats a positive integer number starting with the digit at10^exp.- Parameters:
number- The number to formatexp- The start digitomitTrailingZeros- Whether the formatting should stop if only trailing zeros are left. This is needed e.g. when formatting fractions of a number.asciiBuffer- The buffer to write the ASCII digits tostartOffset- The start offset into the buffer to start writing- Returns:
- The offset into the buffer which contains the first byte that was not filled by the method
-
getExponent
private static int getExponent(long number) Returns the highest exponent of 10 where10^exp < numberfor numbers > 0
-