public class NumberFormatUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
MAX_FRACTION_DIGITS
Maximum number of fraction digits supported by the format methods
|
private static long[] |
POWER_OF_TENS
Contains the power of ten values for fast lookup in the format methods
|
private static int[] |
POWER_OF_TENS_INT |
Modifier | Constructor and Description |
---|---|
private |
NumberFormatUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
formatFloatFast(float value,
int maxFractionDigits,
byte[] asciiBuffer)
Fast variant to format a floating point value to a ASCII-string.
|
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 . |
private static int |
getExponent(long number)
Returns the highest exponent of 10 where
10^exp < number for numbers > 0 |
private static final int MAX_FRACTION_DIGITS
private static final long[] POWER_OF_TENS
private static final int[] POWER_OF_TENS_INT
public static int formatFloatFast(float value, int maxFractionDigits, byte[] asciiBuffer)
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.value
- The float value to formatmaxFractionDigits
- The maximum number of fraction digits usedasciiBuffer
- The output buffer to write the formatted value to-1
if formatting failedprivate static int formatPositiveNumber(long number, int exp, boolean omitTrailingZeros, byte[] asciiBuffer, int startOffset)
10^exp
.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 writingprivate static int getExponent(long number)
10^exp < number
for numbers > 0