Top Description Fields Constructors Methods
org.apache.pdfbox.util

public Class NumberFormatUtil

extends Object
Class Inheritance

This class contains methods to format numbers.
Author
Michael Doswald

Field Summary

Modifier and TypeField and Description
private static final int
MAX_FRACTION_DIGITS

Maximum number of fraction digits supported by the format methods

private static final long[]
POWER_OF_TENS

Contains the power of ten values for fast lookup in the format methods

private static final int[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

The number of bytes used in the buffer or -1 if formatting failed
formatFloatFast
(float
The float value to format
value
,
int
The maximum number of fraction digits used
maxFractionDigits
,
byte[]
The output buffer to write the formatted value to
asciiBuffer
)

Fast variant to format a floating point value to a ASCII-string.

private static int

Returns:

The offset into the buffer which contains the first byte that was not filled by the method
formatPositiveNumber
(long
The number to format
number
,
int
The start digit
exp
,
boolean
Whether the formatting should stop if only trailing zeros are left. This is needed e.g. when formatting fractions of a number.
omitTrailingZeros
,
byte[]
The buffer to write the ASCII digits to
asciiBuffer
,
int
The start offset into the buffer to start writing
startOffset
)

Formats a positive integer number starting with the digit at 10^exp.

private static int
getExponent(long number)

Returns the highest exponent of 10 where 10^exp < number for numbers > 0

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_FRACTION_DIGITSback to summary
private static final int MAX_FRACTION_DIGITS

Maximum number of fraction digits supported by the format methods

POWER_OF_TENSback to summary
private static final long[] POWER_OF_TENS

Contains the power of ten values for fast lookup in the format methods

POWER_OF_TENS_INTback to summary
private static final int[] POWER_OF_TENS_INT

Constructor Detail

NumberFormatUtilback to summary
private NumberFormatUtil()

Method Detail

formatFloatFastback to summary
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:float

The float value to format

maxFractionDigits:int

The maximum number of fraction digits used

asciiBuffer:byte[]

The output buffer to write the formatted value to

Returns:int

The number of bytes used in the buffer or -1 if formatting failed

formatPositiveNumberback to summary
private static int formatPositiveNumber(long number, int exp, boolean omitTrailingZeros, byte[] asciiBuffer, int startOffset)

Formats a positive integer number starting with the digit at 10^exp.

Parameters
number:long

The number to format

exp:int

The start digit

omitTrailingZeros:boolean

Whether the formatting should stop if only trailing zeros are left. This is needed e.g. when formatting fractions of a number.

asciiBuffer:byte[]

The buffer to write the ASCII digits to

startOffset:int

The start offset into the buffer to start writing

Returns:int

The offset into the buffer which contains the first byte that was not filled by the method

getExponentback to summary
private static int getExponent(long number)

Returns the highest exponent of 10 where 10^exp < number for numbers > 0