Package org.apache.commons.text.numbers
Class DoubleFormat.AbstractDoubleFormat
java.lang.Object
org.apache.commons.text.numbers.DoubleFormat.AbstractDoubleFormat
- All Implemented Interfaces:
DoubleFunction<String>,ParsedDecimal.FormatOptions
- Direct Known Subclasses:
DoubleFormat.EngineeringDoubleFormat,DoubleFormat.MixedDoubleFormat,DoubleFormat.PlainDoubleFormat,DoubleFormat.ScientificDoubleFormat
- Enclosing class:
DoubleFormat
private abstract static class DoubleFormat.AbstractDoubleFormat
extends Object
implements DoubleFunction<String>, ParsedDecimal.FormatOptions
Base class for standard double formatting classes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanFlag indicating if exponent values should always be included, even if zero.private final charDecimal separator character.private final char[]String containing the digits 0-9.private final char[]Exponent separator character.private final booleanFlag determining if fraction placeholders should be used.private final charThousands grouping separator.private final booleanFlag indicating if thousands should be grouped.private final intMaximum precision; 0 indicates no limit.private final intMinimum decimal exponent.private final charMinus sign character.private final StringString representing NaN.private final StringString representing negative infinity.private final StringString representing positive infinity.private final booleanFlag determining if signed zero strings are allowed. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDoubleFormat(DoubleFormat.Builder builder) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionapply(double d) private StringapplyFinite(double d) Returns a formatted string representation of the given finite value.protected abstract StringReturns a formatted representation of the given rounded decimal value todst.charGet the decimal separator character.char[]Get an array containing the localized digit characters 0-9 in that order.char[]Get the exponent separator as an array of characters.charGet the character used to separate thousands groupings.charGet the minus sign character.booleanReturntrueif exponent values should always be included in formatted output, even if the value is zero.booleanReturntrueif thousands should be grouped.booleanReturntrueif fraction placeholders (e.g.,".0"in"1.0") should be included.booleanReturntrueif the string zero should be prefixed with the minus sign for negative zero values.
-
Field Details
-
maxPrecision
private final int maxPrecisionMaximum precision; 0 indicates no limit. -
minDecimalExponent
private final int minDecimalExponentMinimum decimal exponent. -
positiveInfinity
String representing positive infinity. -
negativeInfinity
String representing negative infinity. -
nan
String representing NaN. -
fractionPlaceholder
private final boolean fractionPlaceholderFlag determining if fraction placeholders should be used. -
signedZero
private final boolean signedZeroFlag determining if signed zero strings are allowed. -
digits
private final char[] digitsString containing the digits 0-9. -
decimalSeparator
private final char decimalSeparatorDecimal separator character. -
groupingSeparator
private final char groupingSeparatorThousands grouping separator. -
groupThousands
private final boolean groupThousandsFlag indicating if thousands should be grouped. -
minusSign
private final char minusSignMinus sign character. -
exponentSeparatorChars
private final char[] exponentSeparatorCharsExponent separator character. -
alwaysIncludeExponent
private final boolean alwaysIncludeExponentFlag indicating if exponent values should always be included, even if zero.
-
-
Constructor Details
-
AbstractDoubleFormat
AbstractDoubleFormat(DoubleFormat.Builder builder) Constructs a new instance.- Parameters:
builder- builder instance containing configuration values
-
-
Method Details
-
apply
- Specified by:
applyin interfaceDoubleFunction<String>
-
applyFinite
Returns a formatted string representation of the given finite value.- Parameters:
d- double value
-
applyFiniteInternal
Returns a formatted representation of the given rounded decimal value todst.- Parameters:
val- value to format- Returns:
- a formatted representation of the given rounded decimal value to
dst.
-
getDecimalSeparator
public char getDecimalSeparator()Get the decimal separator character.- Specified by:
getDecimalSeparatorin interfaceParsedDecimal.FormatOptions- Returns:
- decimal separator character
-
getDigits
public char[] getDigits()Get an array containing the localized digit characters 0-9 in that order. This string must be non-null and have a length of 10.- Specified by:
getDigitsin interfaceParsedDecimal.FormatOptions- Returns:
- array containing the digit characters 0-9
-
getExponentSeparatorChars
public char[] getExponentSeparatorChars()Get the exponent separator as an array of characters.- Specified by:
getExponentSeparatorCharsin interfaceParsedDecimal.FormatOptions- Returns:
- exponent separator as an array of characters
-
getGroupingSeparator
public char getGroupingSeparator()Get the character used to separate thousands groupings.- Specified by:
getGroupingSeparatorin interfaceParsedDecimal.FormatOptions- Returns:
- character used to separate thousands groupings
-
getMinusSign
public char getMinusSign()Get the minus sign character.- Specified by:
getMinusSignin interfaceParsedDecimal.FormatOptions- Returns:
- minus sign character
-
isAlwaysIncludeExponent
public boolean isAlwaysIncludeExponent()Returntrueif exponent values should always be included in formatted output, even if the value is zero.- Specified by:
isAlwaysIncludeExponentin interfaceParsedDecimal.FormatOptions- Returns:
trueif exponent values should always be included
-
isGroupThousands
public boolean isGroupThousands()Returntrueif thousands should be grouped.- Specified by:
isGroupThousandsin interfaceParsedDecimal.FormatOptions- Returns:
trueif thousand should be grouped
-
isIncludeFractionPlaceholder
public boolean isIncludeFractionPlaceholder()Returntrueif fraction placeholders (e.g.,".0"in"1.0") should be included.- Specified by:
isIncludeFractionPlaceholderin interfaceParsedDecimal.FormatOptions- Returns:
trueif fraction placeholders should be included
-
isSignedZero
public boolean isSignedZero()Returntrueif the string zero should be prefixed with the minus sign for negative zero values.- Specified by:
isSignedZeroin interfaceParsedDecimal.FormatOptions- Returns:
trueif the minus zero string should be allowed
-