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 boolean
Flag indicating if exponent values should always be included, even if zero.private final char
Decimal separator character.private final char[]
String containing the digits 0-9.private final char[]
Exponent separator character.private final boolean
Flag determining if fraction placeholders should be used.private final char
Thousands grouping separator.private final boolean
Flag indicating if thousands should be grouped.private final int
Maximum precision; 0 indicates no limit.private final int
Minimum decimal exponent.private final char
Minus sign character.private final String
String representing NaN.private final String
String representing negative infinity.private final String
String representing positive infinity.private final boolean
Flag 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 String
applyFinite
(double d) Returns a formatted string representation of the given finite value.protected abstract String
Returns a formatted representation of the given rounded decimal value todst
.char
Get 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.char
Get the character used to separate thousands groupings.char
Get the minus sign character.boolean
Returntrue
if exponent values should always be included in formatted output, even if the value is zero.boolean
Returntrue
if thousands should be grouped.boolean
Returntrue
if fraction placeholders (e.g.,".0"
in"1.0"
) should be included.boolean
Returntrue
if 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:
apply
in 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:
getDecimalSeparator
in 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:
getDigits
in 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:
getExponentSeparatorChars
in interfaceParsedDecimal.FormatOptions
- Returns:
- exponent separator as an array of characters
-
getGroupingSeparator
public char getGroupingSeparator()Get the character used to separate thousands groupings.- Specified by:
getGroupingSeparator
in interfaceParsedDecimal.FormatOptions
- Returns:
- character used to separate thousands groupings
-
getMinusSign
public char getMinusSign()Get the minus sign character.- Specified by:
getMinusSign
in interfaceParsedDecimal.FormatOptions
- Returns:
- minus sign character
-
isAlwaysIncludeExponent
public boolean isAlwaysIncludeExponent()Returntrue
if exponent values should always be included in formatted output, even if the value is zero.- Specified by:
isAlwaysIncludeExponent
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if exponent values should always be included
-
isGroupThousands
public boolean isGroupThousands()Returntrue
if thousands should be grouped.- Specified by:
isGroupThousands
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if thousand should be grouped
-
isIncludeFractionPlaceholder
public boolean isIncludeFractionPlaceholder()Returntrue
if fraction placeholders (e.g.,".0"
in"1.0"
) should be included.- Specified by:
isIncludeFractionPlaceholder
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if fraction placeholders should be included
-
isSignedZero
public boolean isSignedZero()Returntrue
if the string zero should be prefixed with the minus sign for negative zero values.- Specified by:
isSignedZero
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if the minus zero string should be allowed
-