|
ArciMath BigDecimal v2.05 now with BigDecimalFormat |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.text.Format
|
+--be.arci.text.BigDecimalFormat
BigDecimalFormat is an implementation of java.text.Format that parses and formats (large) decimal numbers. Many new options and features of BigDecimalFormat make it much more advanced than the standard java.text.DecimalFormat (we use the unqualified class name DecimalFormat further on). Therefor we decided to let BigDecimalFormat format not only ArciMath BigDecimal numbers, but also all Java's primitive numeric types, Java's standard large number classes java.math.BigInteger and java.math.BigDecimal, and all Number objects having a decimal String representation, like com.ibm.math.BigDecimal and com.tce.math.TBigDecimal.
BigDecimalFormat's parsing is very lenient, to accept common user input styles as well as output from BigDecimalFormat's own format methods.
BigDecimalFormat uses intermediate ArciMath BigDecimal objects for all arithmetic, rounding, and toString() representation.
For access to member descriptions use the navigation bar on top.
Also, BigDecimalFormat uses the ArciMath BigDecimal class for all arithmetic, which offers a very strong protection against overflow both by the range of numbers that can be represented as ArciMath BigDecimal objects, and by ArciMath's performant but safe algorithms, throwing an ArithmeticException on overflow.
BigDecimalFormat outputs decimal digits starting with the DecimalFormatSymbols- defined localized zero digit; as an example the decimal digit 5 is output as (char)(decimalFormatSymbols.getZeroDigit() + 5). During parsing BigDecimalFormat recognizes all Unicode characters that represent decimal digits, as defined by Character.digit(), as well as the ten consecutive characters starting with the localized zero digit defined in the DecimalFormatSymbols object. Thus BigDecimalFormat makes it possible to parse and format numbers in any locale where the decimal digits ocupy 10 consecutive places in de Unicode character table, offering support for Western (ISO-LATIN-1), Arabic-Indic, Extended Arabic-Indic, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Telugu, Kannada, Malayalam, Thai, Lao, Tibetan and Fullwidth digits.
For localization BigDecimalFormat builds on DecimalFormat, rather than directly parsing the localization rules in the java.text.resources.LocaleElements_xx_XX group of classfiles, because the latter are undocumented and indeed differ in different JDK versions.
The default BigDecimalFormat() constructor starts from a default
DecimalFormat object. The BigDecimalFormat(DecimalFormat)
constructor accepts the localized DecimalFormat objects typically delivered
by calls to java.text.NumberFormat's getNumberInstance,
getCurrencyInstance, getPercentInstance and
getScientificInstance methods.
(Currently, upto JDK13, all of these methods in NumberFormat are
hardcoded to return a DecimalFormat object, even though it is documented that
for some locales NumberFormat might return another type).
DecimalFormat patterns should all be compatible with BigDecimalFormat,
though the reverse is certainly not true.
The usual symbol for indicating the exponent is "E", but the user can set any other String to be used as exponent symbol (this should be a feature of DecimalFormatSymbols, but it isn't, and because DecimalFormatSymbols is final we made it a feature of BigDecimalFormat itself).
Negative exponents are formatted using the localized minus sign, not the prefix and suffix from the negative subpattern. This allows notations such as "(1.17E+5)" for the value -117,000. For positive exponents the user can specify to show a plus sign following the exponent symbol or not.
With exponent increments, formatting rounds the number to the sum of the actual integer digits that will be shown and the maximum number of decimal places (in DecimalFormat the number of formatted digits is fixed at 1 + the number of decimal places, making that some digits may get shifted from the decimal places into the integer field to make the exponent a multiple of it's increment). For example the pattern "000.0000E+03" sets a fixed length engineering format with 3 integer digits and 4 decimal places, and an exponent value of 2 digits.
setZeroPaddingChar().
The latter kind may be specified either through the API or through
the pattern syntax. Alignment is made easier if you keep positive and negative
prefix and positive and negative suffixes the same length.
For example, you can use FieldPosition to align numbers on the decimal point in two ways:
Note: JDK1.1 We cannot set the FieldPosition indexes in the JDK1.1.x version, due to a bug in java.text.FieldPosition (package private access to the relevant methods). However, we have noticed that the Java 2 version of BigDecimalFormat, that does set the FieldPosition indexes, works fine on Sun's JDK1.1.x virtual machines; apparently these virtual machines check for method accessibility at compile time only, not at runtime. As the FieldPosition treatment is the only difference between the JDK1.1 and Java2 versions of BigDecimalFormat, you could use the Java2 version on these virtual machines.
strict parsing adherence to the different
parts in a BigDecimal pattern.
If BigDecimalFormat.parse(String, ParsePosition) fails to parse
a String, it returns null and leaves the parse position
unchanged. The convenience method BigDecimalFormat.parse(String)
indicates parse failure by throwing a ParseException.
Here are the rules for lenient parsing; see the description of strict parsing
for possible areas of strict parsing:
parse integer only is set, parsing stops at the decimal separator, if any.
Decimal places, exponent or suffix that are present in the input but that
come after a decimal separator are ignored. ParsePosition index is set
at that decimal separator.
applyPattern() and
applyLocalizedPattern(), or indirectly using the API methods. When
using the default BigDecimalFormat() or the
BigDecimalFormat(DecimalFormat) constructors, the pattern and symbols
are read from the (default) DecimalFormat object.
Contains:
decimalFormatSymbols: these are the symbols used in localized patterns,
in format() and in parse()
exponentSymbol: logically belongs to DecimalFormatSymbols
parseIntegerOnly: is deprecated, affects parsing only
parsingStrictness: affects parsing only, sets the degree
to which a parsed number String should complie with different parts of a BigDecimalFormat
pattern.
plusSign: logically belongs to DecimalFormatSymbols
retainZeroTail: is in a strict sense a property of ArciMath BigDecimal, which
you can choose to respect in BigDecimalFormat.
rounding mode: sets the rounding mode used in calculations for truncating formatted
numbers and for applying multiplier and smallestModule
signalOverflow: sets strict interpretation of pattern maxima
smallestModule: can only be set through a pattern as a fixed point number, not if
exponential notation is needed to specify the smallestModule
zeroPaddingChar: we already had mixed feelings about the padding escape, so we decided not
to introduce another notation for the zeroPaddingChar
decimal separator
|
integer | decimal exponent
/ \|/ \ / \
(optional prefix)#,###,#00.0000####E+000##(optional suffix)
/ \ / ^
last grouping grouping optional, to always
separator size show the exponent sign
| + | repeat ('1 or more instances of') |
|---|---|
| * | repeat optional ('0 or more instances of') |
| { } | optional ('0 or 1 instances of') |
| [ X | Y | ... | Z ] | choose ('1 of the choices X to Z') |
| ( ) | group ('treat enclosed grammar specification as 1 symbol') |
| X..Y | range ('any of X up to Y, inclusive') |
| S - T | exclude ('symbols in S, except those in T') |
currencySign := '¤'
'¤' is Unicode character '\u00A4'
decimalSep := [ '.' | localizedDecimalSeparator ]
digitPlace := [ '#' | localizedDigit ]
exponentSymbol := [ "E" | localizedExponentSymbol ]
groupingSep := [ ',' | localizedGroupingSeparator ]
padEscape := '^'
patternSep := [ ';' | localizedPatternSeparator ]
percent := [ '%' | localizedPercent ]
perMille := [ '' | localizedPerMill ]
'' is Unicode character '\u2030'
plusSign := [ '+' | localizedPlusSign ]
quote := '\''
The single quote character
zeroDigit := [ '0' | localizedZeroDigit ]
nonZeroDigit := (zeroDigit + 1..9)
This is an arithmetic sum!
digit := [ zeroDigit | nonZeroDigit ]
char := [ ( '\u0000'..'\uFFFD' - quote ) | ( quote quote ) ]
expandedChar := [ percent |
perMille |
currencySign |
( currencySign currencySign ) ]
specialChar := [ currencySign |
decimalSep |
digit |
digitPlace |
groupingSep |
padEscape |
patternSep |
percent |
perMille ]
unquotedChar := [ ( char - specialChar ) | expandedChar ]
quotedChars := quote char+ quote
Grammar
pattern := posPattern { patternSep negPattern }
posPattern := subPattern
negPattern := subPattern
subPattern := [ ( { paddedPrefix } number { suffix } ) |
( { prefix } paddedNumber { suffix } ) |
( { prefix } number { paddedSuffix } ) ]
paddedPrefix := paddedAffix
paddedSuffix := paddedAffix
paddedAffix := [ ( padSpec affix ) | ( affix padSpec ) ]
prefix := affix
suffix := affix
affix := [ unquotedChar | quotedChars ]+
padSpec := padEscape padChar
padChar := char
paddedNumber := fixedPoint { padSpec } exponent
number := fixedPoint exponent
fixedPoint := [ integer |
( integer decimalSep ) |
( { integer } decimalSep mantissa ) ]
integer := [ minIntDigits+ |
( maxIntDigits+ minIntDigits* ) ]
minIntDigits := { groupingSep } digit+
maxIntDigits := { groupingSep } digitPlace+
mantissa := [ minDecPlaces |
( { minDecPlaces } maxDecPlaces ) ]
minDecPlaces := digit+
maxDecPlaces := digitPlace+
exponent := exponentSymbol { plusSign } exponentValue
exponentValue := [ minExpDigits |
( { minExpDigits } maxExpDigits ) ]
minExpDigits := digit+
maxExpDigits := digitPlace+
BigDecimal,
MathContext, Serialized Form| Field Summary | |
static int |
BASE_NUMBER_FIELD
Field constant that can be used to construct a FieldPosition object. |
static char |
CURRENCY_SIGN
The CURRENCY_SIGN is the standard Unicode symbol for currency. |
static int |
DECIMAL_FRACTION_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
DECIMAL_SEPARATOR_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
EXPONENT_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
EXPONENT_SIGN_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
EXPONENT_SYMBOL_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
EXPONENT_VALUE_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
INTEGER_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
NUMBER_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
PAD_AFTER_PREFIX
Constant for getPaddingPosition() and setPaddingPosition(), specifying to insert padding characters after the prefix. |
static int |
PAD_AFTER_SUFFIX
Constant for getPaddingPosition() and setPaddingPosition(), specifying to insert padding characters after the suffix. |
static int |
PAD_BEFORE_EXPONENT
Constant for getPaddingPosition() and setPaddingPosition(), specifying to insert padding characters before the exponent. |
static int |
PAD_BEFORE_PREFIX
Constant for getPaddingPosition() and setPaddingPosition(), specifying to insert padding characters before the prefix. |
static int |
PAD_BEFORE_SUFFIX
Constant for getPaddingPosition() and setPaddingPosition(), specifying to insert padding characters before the suffix. |
static int |
PADDING_FIELD
Field constant that can be used to construct a FieldPosition object. |
static int |
PARSE_LENIENT
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), specifying lenient parsing of number Strings. |
static int |
PARSE_MATCH_AFFIXES
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(). |
static int |
PARSE_MATCH_EXPONENT_SYMBOL
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), allowing only the exponent symbol set for the BigDecimalFormat as exponent symbol in a number String. |
static int |
PARSE_MATCH_GROUPING
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), requiring digit grouping if the grouping size set for the BigDecimalFormat is not zero. |
static int |
PARSE_MATCH_PADDING_CHAR
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), accepting only the padding character set for the BigDecimalFormat as padding in a number String. |
static int |
PARSE_MATCH_PADDING_POS
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), requiring any padding in a number String to occur at the padding position set for the BigDecimalFormat. |
static int |
PARSE_MATCH_PADDING_WIDTH
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), to enforce a correct number of padding characters. |
static int |
PARSE_MATCH_PREFIX
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), requiring a match with either the positive or the negative prefix when parsing a number String. |
static int |
PARSE_MATCH_SEPARATOR_CHARS
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), allowing only the grouping separator and the decimal (or monetary decimal for currency formats) separator characters set for the BigDecimalFormat's java.text.DecimalFormatSymbols as separator characters in a number String. |
static int |
PARSE_MATCH_SIGN_CHARS
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), allowing only the plus sign and minus sign set for the BigDecimalFormat or it's java.text.DecimalFormatSymbols as sign character in a number String. |
static int |
PARSE_MATCH_SUFFIX
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(), requiring a match with either the positive or the negative suffix when parsing a number String. |
static int |
PARSE_STRICT
Parsing strictness constant for getParsingStrictness() and setParsingStrictness(). |
static char |
PER_MILLE_SIGN
The PER_MILLE_SIGN is the standard Unicode symbol for per mille. |
static char |
PERCENT_SIGN
The PERCENT_SIGN is the standard Unicode symbol for percent. |
static int |
PREFIX_FIELD
Field constant that can be used to construct a FieldPosition object. |
static char |
QUOTE
The single quote character to embed special characters in pattern affixes |
static int |
SUFFIX_FIELD
Field constant that can be used to construct a FieldPosition object. |
| Constructor Summary | |
BigDecimalFormat()
Create a BigDecimalFormat using the default pattern and symbols for the default locale. |
|
BigDecimalFormat(java.text.DecimalFormat dfmt)
Convenience method to construct a localized BigDecimalFormat, based on e.g. one of the standard DecimalFormat's for a given locale, obtained using the factory methods on NumberFormat such as getInstance or getCurrencyInstance. |
|
BigDecimalFormat(java.lang.String sPattern)
Create a BigDecimalFormat from the given pattern and the symbols for the default locale. |
|
BigDecimalFormat(java.lang.String sPattern,
java.text.DecimalFormatSymbols dfsSymbols)
Create a BigDecimalFormat from the given pattern and symbols. |
|
BigDecimalFormat(java.lang.String sPattern,
java.util.Locale locale)
Create a BigDecimalFormat from the given pattern and the symbols for the given locale. |
|
| Method Summary | |
void |
applyLocalizedPattern(java.lang.String sLocalizedPattern)
Apply the given localized pattern to this BigDecimalFormat object. |
void |
applyPattern(java.lang.String sPattern)
Apply the given pattern to this BigDecimalFormat object. |
java.lang.Object |
clone()
Standard override; no change in semantics. |
boolean |
equals(java.lang.Object obj)
Overrides equals |
java.lang.String |
format(java.math.BigDecimal bdNumber)
Convenience method which formats a java.math.BigDecimal value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.String |
format(BigDecimal bdNumber)
Convenience method which formats an ArciMath BigDecimal value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.StringBuffer |
format(java.math.BigDecimal bdNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Format a java.math.BigDecimal number. |
java.lang.StringBuffer |
format(BigDecimal bdNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Format an ArciMath BigDecimal number. |
java.lang.String |
format(java.math.BigInteger biNumber)
Convenience method which formats a BigInteger value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.StringBuffer |
format(java.math.BigInteger biNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Format a BigInteger number. |
java.lang.String |
format(double dNumber)
Convenience method which formats the decimal String representation of a double value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.StringBuffer |
format(double dNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Formats a double value, with proper rendering of NaN and Infinite values. |
java.lang.String |
format(long lNumber)
Convenience method which formats a long value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.StringBuffer |
format(long lNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Format a long value. |
java.lang.String |
format(java.lang.Number number)
Convenience method which formats the toString() representation of a Number value to a String according to the pattern represented by this BigDecimalFormat. |
java.lang.StringBuffer |
format(java.lang.Number number,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Format a Number. |
java.lang.StringBuffer |
format(java.lang.Object oNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Formats an object to produce a string. |
boolean |
getCurrencyFormat()
true if this object represents a currency format. |
java.text.DecimalFormatSymbols |
getDecimalFormatSymbols()
Returns a clone of the decimal format symbols used by this BigDecimalFormat; changes to the returned object thus have no influence on the BigDecimalFormat. |
boolean |
getDecimalSeparatorAlwaysShown()
Returns wether the decimal separator is shown with integer numbers. |
boolean |
getExponentialNotation()
Return whether or not exponential notation is used. |
int |
getExponentIncrement()
Return the exponent increment used with exponential notation. |
boolean |
getExponentSignAlwaysShown()
Return whether the exponent sign is always shown. |
java.lang.String |
getExponentSymbol()
Get the symbol indicating the exponent in exponential notation and localized patterns. |
int |
getGroupingSize()
Return the grouping size. |
int |
getMaximumDecimalPlaces()
Returns the maximum number of digits to format in the decimal fraction of a number; this value has no effect on parsing. |
int |
getMaximumExponentDigits()
Return the maximum number of digits to format in the exponent value of a number with exponential notation; this value has no effect on parsing. |
int |
getMaximumIntegerDigits()
Returns the maximum number of digits to format in the integer portion of a number; this value has no effect on parsing. |
int |
getMinimumDecimalPlaces()
Returns the minimum number of digits to format in the decimal fraction of a number; this value has no effect on parsing. |
int |
getMinimumExponentDigits()
Return the minimum number of digits required in the exponent value of a number with exponential notation. |
int |
getMinimumIntegerDigits()
Returns the minimum number of digits required in the integer portion of a number. |
int |
getMultiplier()
Get the multiplier for use in percent, permill, etc. |
java.lang.String |
getNegativePrefix()
Get the negative prefix. |
java.lang.String |
getNegativeSuffix()
Get the negative suffix. |
char |
getPaddingChar()
Get the character used to pad a formatted number to the padding width. |
int |
getPaddingPosition()
Get the position at which to pad a formatted number that is shorter than the padding width. |
int |
getPaddingWidth()
Get the width to which the output of format() is to be padded. |
boolean |
getParseIntegerOnly()
Returns true if this format will parse numbers as integers only. |
int |
getParsingStrictness()
Returns the parsing strictness for this BigDecimalFormat. |
char |
getPlusSign()
Get the symbol indicating the localized plus sign. |
java.lang.String |
getPositivePrefix()
Get the positive prefix. |
java.lang.String |
getPositiveSuffix()
Get the positive suffix. |
boolean |
getRetainZeroTail()
Returns whether trailing zero digits in a number will be formatted as significand. |
int |
getRoundingMode()
Get the rounding mode used in rounding numbers to the maximum decimal places and to multiples of the smallest module, and in dividing parsed numbers by the multiplier property. |
boolean |
getSignalOverflow()
Return whether or not overflow is signalled during formatting. |
BigDecimal |
getSmallestModule()
Get the smallest modules to which this BigDecimalFormat rounds formatted numbers. |
int |
getZeroPaddingChar()
Get the character used to replace non-significant zeroes. |
int |
hashCode()
Overrides hashCode |
BigDecimal |
parse(java.lang.String sNumber)
Convenience method to parse a number from a String. |
BigDecimal |
parse(java.lang.String sNumber,
java.text.ParsePosition ppStatus)
Returns an ArciMath BigDecimal number parsed from the String argument. |
java.lang.Object |
parseObject(java.lang.String sNumber,
java.text.ParsePosition ppStatus)
Parses a String to produce an ArciMath BigDecimal object. |
void |
setCurrencyFormat(boolean swCurrencyFormat)
Set to true if this object has to represent a currency format. |
void |
setDecimalFormatSymbols(java.text.DecimalFormatSymbols dfsSymbols)
Sets the decimal format symbols to a clone of the argument; later changes to the argument thus have no influence on the BigDecimalFormat. |
void |
setDecimalSeparatorAlwaysShown(boolean swDecimalSeparatorAlwaysShown)
Sets wether the decimal separator is to be shown with integer numbers. |
void |
setExponentialNotation(boolean swExponentialNotation)
Set whether or not exponentional notation is used. |
void |
setExponentIncrement(int iExponentIncrement)
Sets the exponent increment used with exponential notation. |
void |
setExponentSignAlwaysShown(boolean swExponentSignAlwaysShown)
Set whether the exponent sign is always shown. |
void |
setExponentSymbol(java.lang.String sExponentSymbol)
Set the symbol indicating the exponent in exponential notation and localized patterns. |
void |
setGroupingSize(int iGroupingSize)
Set the grouping size. |
void |
setMaximumDecimalPlaces(int iMaximumDecimalPlaces)
Sets the maximum number of digits to format in the decimal fraction of a number; this value has no effect on parsing. maximumDecimalPlaces must be >= minimumDecimalPlaces. |
void |
setMaximumExponentDigits(int iMaximumExponentDigits)
Set the maximum number of digits to format in the exponent value of a number with exponential notation; this value has no effect on parsing. |
void |
setMaximumIntegerDigits(int iMaximumIntegerDigits)
Sets the maximum number of digits to format in the integer portion of a number; this value has no effect on parsing. maximumIntegerDigits must be >= minimumIntegerDigits. |
void |
setMinimumDecimalPlaces(int iMinimumDecimalPlaces)
Sets the minimum number of digits to format in the decimal fraction of a number; this value has no effect on parsing. minimumDecimalPlaces must be <= maximumDecimalPlaces. |
void |
setMinimumExponentDigits(int iMinimumExponentDigits)
Set the minimum number of digits required in the exponent value of a number with exponential notation. |
void |
setMinimumIntegerDigits(int iMinimumIntegerDigits)
Sets the minimum number of digits to format in the integer portion of a number; this value has no effect on parsing. minimumIntegerDigits must be <= maximumIntegerDigits. |
void |
setMultiplier(int iMultiplier)
Set the multiplier for use in percent, permill, etc. |
void |
setNegativePrefix(java.lang.String sNegativePrefix)
Set the negative prefix. |
void |
setNegativeSuffix(java.lang.String sNegativeSuffix)
Set the negative suffix. |
void |
setPaddingChar(char cPaddingChar)
Set the character used to pad a formatted number to the padding width. |
void |
setPaddingPosition(int iPaddingPosition)
Set the position at which to pad a formatted number that is shorter than the padding width. |
void |
setPaddingWidth(int iPaddingWidth)
Set the width to which the output of format() is to be padded. |
void |
setParseIntegerOnly(boolean swParseIntegerOnly)
Deprecated. This method is retained for compatibility with DecimalFormat only; we advise to obtain an integer number from the fully parsed ArciMath BigDecimal result, e.g. by the operation bdResult.setScale(0, roundingMode) |
void |
setParsingStrictness(int iParsingStrictness)
Sets the parsing strictness for this BigDecimalFormat. |
void |
setPlusSign(char cPlusSign)
Set the symbol indicating the localized plus sign. |
void |
setPositivePrefix(java.lang.String sPositivePrefix)
Set the positive prefix. |
void |
setPositiveSuffix(java.lang.String sPositiveSuffix)
Set the positive suffix. |
void |
setRetainZeroTail(boolean swRetainZeroTail)
Set whether trailing zero digits in a number will be formatted as significand. |
void |
setRoundingMode(int iRoundingMode)
Get the rounding mode used in rounding numbers to the maximum decimal places and to multiples of the smallest module, and in dividing parsed numbers by the multiplier property. |
void |
setSignalOverflow(boolean swSignalOverflow)
Set whether or not overflow is signalled on formatting. |
void |
setSmallestModule(BigDecimal bdSmallestModule)
Set the smallest modules to which this BigDecimalFormat rounds formatted numbers. |
void |
setZeroPaddingChar(int iZeroPaddingChar)
Set the character used to replace non-significant zeroes. |
| Methods inherited from class java.text.Format |
format, parseObject |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final char QUOTE
public static final char PERCENT_SIGN
setMultiplier(int),
setDecimalFormatSymbols(java.text.DecimalFormatSymbols)public static final char PER_MILLE_SIGN
setMultiplier(int),
setDecimalFormatSymbols(java.text.DecimalFormatSymbols)public static final char CURRENCY_SIGN
The CURRENCY_SIGN is not localized.
public static final int PREFIX_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int INTEGER_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int DECIMAL_SEPARATOR_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int DECIMAL_FRACTION_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int BASE_NUMBER_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int EXPONENT_SYMBOL_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int EXPONENT_SIGN_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int EXPONENT_VALUE_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int EXPONENT_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int NUMBER_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int SUFFIX_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int PADDING_FIELD
Note: In the JDK1.1 version the FieldPosition indexes are not set (see "FieldPosition alignment")
public static final int PAD_BEFORE_PREFIX
setPaddingPosition(int),
getPaddingPosition(),
PAD_AFTER_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_BEFORE_SUFFIX,
PAD_AFTER_SUFFIXpublic static final int PAD_AFTER_PREFIX
setPaddingPosition(int),
getPaddingPosition(),
PAD_BEFORE_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_BEFORE_SUFFIX,
PAD_AFTER_SUFFIXpublic static final int PAD_BEFORE_EXPONENT
setPaddingPosition(int),
getPaddingPosition(),
PAD_BEFORE_PREFIX,
PAD_AFTER_PREFIX,
PAD_AFTER_SUFFIXpublic static final int PAD_BEFORE_SUFFIX
setPaddingPosition(int),
getPaddingPosition(),
PAD_BEFORE_PREFIX,
PAD_AFTER_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_AFTER_SUFFIXpublic static final int PAD_AFTER_SUFFIX
setPaddingPosition(int),
getPaddingPosition(),
PAD_BEFORE_PREFIX,
PAD_AFTER_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_BEFORE_SUFFIXpublic static final int PARSE_LENIENT
setParsingStrictness(int),
getParsingStrictness(),
PARSE_STRICTpublic static final int PARSE_MATCH_PREFIX
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants, except with PARSE_MATCH_SIGN_CHARS.
getPositivePrefix(),
getNegativePrefix(),
setParsingStrictness(int),
getParsingStrictness(),
PARSE_MATCH_SUFFIX,
PARSE_MATCH_AFFIXESpublic static final int PARSE_MATCH_SUFFIX
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
getPositiveSuffix(),
getNegativeSuffix(),
setParsingStrictness(int),
getParsingStrictness(),
PARSE_MATCH_PREFIX,
PARSE_MATCH_AFFIXESpublic static final int PARSE_MATCH_AFFIXES
setParsingStrictness(int),
getParsingStrictness(),
PARSE_MATCH_PREFIX,
PARSE_MATCH_SUFFIXpublic static final int PARSE_MATCH_PADDING_CHAR
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
setParsingStrictness(int),
getParsingStrictness(),
getPaddingChar(),
PARSE_MATCH_PADDING_POS,
PARSE_MATCH_PADDING_WIDTHpublic static final int PARSE_MATCH_PADDING_POS
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
setParsingStrictness(int),
getParsingStrictness(),
getPaddingChar(),
PARSE_MATCH_PADDING_CHAR,
PARSE_MATCH_PADDING_WIDTHpublic static final int PARSE_MATCH_PADDING_WIDTH
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
setParsingStrictness(int),
getParsingStrictness(),
getPaddingChar(),
PARSE_MATCH_PADDING_CHAR,
PARSE_MATCH_PADDING_POSpublic static final int PARSE_MATCH_SIGN_CHARS
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants, except with PARSE_MATCH_PREFIX.
getPlusSign(),
"java.text.DecimalFormatSymbols.getMinusSign()",
setParsingStrictness(int),
getParsingStrictness()public static final int PARSE_MATCH_SEPARATOR_CHARS
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
getCurrencyFormat(),
setParsingStrictness(int),
getParsingStrictness(),
PARSE_MATCH_GROUPINGpublic static final int PARSE_MATCH_EXPONENT_SYMBOL
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
getExponentSymbol(),
setParsingStrictness(int),
getParsingStrictness()public static final int PARSE_MATCH_GROUPING
This constant can be combined ('|' operator) with other PARSE_MATCH_xxx constants.
getGroupingSize(),
setParsingStrictness(int),
getParsingStrictness(),
PARSE_MATCH_SEPARATOR_CHARSpublic static final int PARSE_STRICT
Combination of PARSE_MATCH_AFFIXES, PARSE_MATCH_PADDING_CHAR, PARSE_MATCH_PADDING_POS, PARSE_MATCH_PADDING_WIDTH, PARSE_MATCH_SIGN_CHARS, PARSE_MATCH_SEPARATOR_CHARS, PARSE_MATCH_EXPONENT_SYMBOL, and PARSE_MATCH_GROUPING.
setParsingStrictness(int),
getParsingStrictness(),
PARSE_LENIENT,
PARSE_MATCH_AFFIXES,
PARSE_MATCH_SIGN_CHARS,
PARSE_MATCH_PADDING_CHAR,
PARSE_MATCH_PADDING_POS,
PARSE_MATCH_PADDING_WIDTH,
PARSE_MATCH_SEPARATOR_CHARS,
PARSE_MATCH_GROUPING,
PARSE_MATCH_EXPONENT_SYMBOL| Constructor Detail |
public BigDecimalFormat()
NOTE: See setRoundingMode for a comment on the
rounding mode used.
setRoundingMode(int),
BigDecimalFormat(DecimalFormat dfmt)public BigDecimalFormat(java.text.DecimalFormat dfmt)
NOTE: See setRoundingMode for a comment on the
rounding mode used.
setRoundingMode(int),
"java.text.DecimalFormat",
"java.text.DecimalFormatSymbols",
"java.text.NumberFormat#getInstance",
"java.text.NumberFormat#getNumberInstance",
"java.text.NumberFormat#getCurrencyInstance",
"java.text.NumberFormat#getPercentInstance"public BigDecimalFormat(java.lang.String sPattern)
sPattern - A non-localized pattern string.java.lang.IllegalArgumentException - if the given pattern is invalid.
public BigDecimalFormat(java.lang.String sPattern,
java.util.Locale locale)
sPattern - A non-localized pattern string.locale - the Locale to construct the java.lang.IllegalArgumentException - if the given pattern is invalid.
public BigDecimalFormat(java.lang.String sPattern,
java.text.DecimalFormatSymbols dfsSymbols)
sPattern - a non-localized pattern stringdfsSymbols - the set of symbols to be used. A clone of this object
is used by the constructed BigDecimalFormat, so any later changes to dfsSymbols
have no effect on the constructed BigDecimalFormat.java.lang.IllegalArgumentException - if the given pattern is invalid| Method Detail |
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.Object clone()
clone in class java.text.Format
public java.lang.StringBuffer format(java.lang.Object oNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
format in class java.text.FormatoNumber - The Number object to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.java.lang.IllegalArgumentException - when the oNumber argument is not a Number,
or cannot be converted into an ArciMath BigDecimal object.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.BigDecimal.BigDecimal(String),
format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos),
"java.text."
public java.lang.Object parseObject(java.lang.String sNumber,
java.text.ParsePosition ppStatus)
This java.text.Format subclass supplies specific parse methods that return ArciMath BigDecimal objects (since methods can't overload on return types, these are named parse), and to which parseObject delegates.
Note:
The contract for java.text.Format.parseObject() is to discard leading
whitespace. However both java.text.NumberFormat.parseObject()
and DecimalFormat.parse() break that contract and do not accept leading
whitespace. Even though we are a direct subclass of java.text.Format,
we choose to follow the behaviour of DecimalFormat, for which BigDecimalFormat
claims to be a replacement. In the default lenient parsing mode however we do
accept leading space characters and leading padding characters.
parseObject in class java.text.FormatsNumber - String containing the number to parse, starting at th index of
ppStatusppStatus - Input-Output parameter. Before calling, set ppStatus.index
to the offset you want to start parsing at in sNumber. After return,
ppStatus.index is the end of the text you parsed; if an error occurs, this index
is unchanged.parse(String sNumber, ParsePosition ppStatus),
PARSE_LENIENT,
"java.text.ParsePosition"public java.lang.String format(double dNumber)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(double dNumber, StringBuffer sbToAppendTo, FieldPosition fPos)public java.lang.String format(long lNumber)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(long lNumber, StringBuffer sbToAppendTo, FieldPosition fPos)public java.lang.String format(java.math.BigInteger biNumber)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(java.math.BigInteger biNumber, StringBuffer sbToAppendTo, FieldPosition fPos)public java.lang.String format(java.math.BigDecimal bdNumber)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(java.math.BigDecimal bdNumber, StringBuffer sbToAppendTo, FieldPosition fPos)public java.lang.String format(java.lang.Number number)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(Number number, StringBuffer sbToAppendTo, FieldPosition fPos)public final java.lang.String format(BigDecimal bdNumber)
FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bdNumber, StringBuffer sbToAppendTo, FieldPosition fPos)
public java.lang.StringBuffer format(double dNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
Special Cases
NaN is typically formatted as the single character String \uFFFD. This String is determined by the DecimalFormatSymbols object. The empty String replaces any positive and negative prefix or suffix in the formatted output, because NaN has no sign. The NaN symbol String is regarded as the first and only part of the NUMBER_FIELD, which is neither in the BASE_NUMBER_FIELD nor in the EXPONENT_FIELD.
Infinity is typically formatted as the single character String \u221E, with the positive or negative prefixes and suffixes applied. This String is determined by the DecimalFormatSymbols object. The Infinity symbol String is regarded as the first and only part of the NUMBER_FIELD, which is neither in the BASE_NUMBER_FIELD nor in the EXPONENT_FIELD.
dNumber - The double value to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos)
public java.lang.StringBuffer format(long lNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
lNumber - The long value to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos)
public java.lang.StringBuffer format(java.math.BigInteger biNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
biNumber - The BigInteger value to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos)
public java.lang.StringBuffer format(java.math.BigDecimal bdNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
bdNumber - The java.math.BigDecimal value to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos)
public java.lang.StringBuffer format(java.lang.Number number,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
number - The Number object to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.java.lang.IllegalArgumentException - if the toString() representation
of the number is not a decimal representation that is understood by ArciMath BigDecimal.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(BigDecimal bd, StringBuffer sbToAppendTo, FieldPosition fPos),
BigDecimal.BigDecimal(String)
public java.lang.StringBuffer format(BigDecimal bdNumber,
java.lang.StringBuffer sbToAppendTo,
java.text.FieldPosition fPos)
bdNumber - The ArciMath BigDecimal value to format.sbToAppendTo - where the text is to be appendedfPos - an alignment field, if desired, or null; on output the offsets of
the alignment field are filled in. The field property of fPos
must be one of the predefined xxx_FIELD constants of BigDecimalFormat.FormatOverflowException - if signalOverflow is set and the formatted number, after truncation
to maximum decimal places, does not fit into maximum integer digits and maximum exponent digits.format(Object oNumber, StringBuffer sbToAppendTo, FieldPosition fPos)
public BigDecimal parse(java.lang.String sNumber)
throws java.text.ParseException
java.text.ParseException - if the specified string is invalid.parse(String sNumber, ParsePosition ppStatus),
parseObject(String sNumber, ParsePosition ppStatus)
public BigDecimal parse(java.lang.String sNumber,
java.text.ParsePosition ppStatus)
When parsing, leading whitespace is discarded (with successful parse), while trailing whitespace is left as is.
Example: Parsing " 12 xy" for a number, with ppStatus.getIndex() == 0 on entry, will parse the number 12, with ppStatus.getIndex() == 3 on exit (just before the second space). Parsing a second time will return null,since "xy" is not a number, and leave ppStatus.getIndex() at 3.
If ParseIntegerOnly is set, parsing will stop at a decimal point, thus not seeing any sign indicated by a suffix or any exponent. Does not throw an exception; if no object can be parsed, the return value is null and the index of ppStatus is unchanged.
sNumber - String containing the number to parse, starting at th index of
ppStatusppStatus - Input-Output parameter. Before calling, use ppStatus.setIndex
to set the offset you want to start parsing at in sNumber. After return,
ppStatus.getIndex gives the end of the text you parsed; if an error occurs, this index
is unchanged. In the Java 2 version, ppStatus.getErrorIndex can be checked for the
position that caused the parsing error.setParseIntegerOnly(boolean),
parseObject(String sNumber, ParsePosition ppStatus),
"java.text.ParsePosition"public void applyPattern(java.lang.String sPattern)
sPattern - a formatting pattern complying with the pattern syntax for BigDecimalFormatapplyLocalizedPattern(java.lang.String),
getDecimalFormatSymbols(),
getExponentSymbol(),
BigDecimalFormatpublic void applyLocalizedPattern(java.lang.String sLocalizedPattern)
sPattern - a formatting pattern complying with the pattern syntax for BigDecimalFormatapplyLocalizedPattern(java.lang.String),
getDecimalFormatSymbols(),
getExponentSymbol(),
BigDecimalFormatpublic java.text.DecimalFormatSymbols getDecimalFormatSymbols()
setDecimalFormatSymbols(java.text.DecimalFormatSymbols),
"java.text.DecimalFormatSymbols"public void setDecimalFormatSymbols(java.text.DecimalFormatSymbols dfsSymbols)
dfsSymbols - desired getDecimalFormatSymbols(),
"java.text.DecimalFormatSymbols"public java.lang.String getExponentSymbol()
public void setExponentSymbol(java.lang.String sExponentSymbol)
public char getPlusSign()
public void setPlusSign(char cPlusSign)
public boolean getSignalOverflow()
setSignalOverflow(boolean)public void setSignalOverflow(boolean swSignalOverflow)
This property can only be set by this method; it can not be set, nor will it be changed, by applying a pattern.
A common use of SignalOverflow would be to switch to exponential notation if a number is too long for fixed point notation, as in this example:
BigDecimalFormat bdfFixedPoint = new BigDecimalFormat("##,##0.####");//these patterns have
BigDecimalFormat bdfScientific = new BigDecimalFormat("0.####E+###");//equal maximum length
String s;
try {
s = bdfFixedPoint.format(myNumber);
}
catch (FormatOverflowException e) {
s = bdfScientific.format(myNumber);
}
getSignalOverflow()public java.lang.String getPositivePrefix()
Examples: +123, $123, sFr123
public void setPositivePrefix(java.lang.String sPositivePrefix)
sPositivePrefix - the new prefix to use for positive numbers. Special
characters like the currency sign '¤', the percent sign '%' and the per
mille sign '‰' are not interpreted nor expanded, as if sPositivePrefix
was put between quotes in a pattern.public java.lang.String getPositiveSuffix()
public void setPositiveSuffix(java.lang.String sPositiveSuffix)
sPositiveSuffix - the new prefix to use for positive numbers. Special
characters like the currency sign '¤', the percent sign '%' and the per
mille sign '‰' are not interpreted nor expanded, as if sPositiveSuffix
was put between quotes in a pattern.public java.lang.String getNegativePrefix()
public void setNegativePrefix(java.lang.String sNegativePrefix)
sNegativePrefix - the new prefix to use for positive numbers. Special
characters like the currency sign '¤', the percent sign '%' and the per
mille sign '‰' are not interpreted nor expanded, as if sNegativePrefix
was put between quotes in a pattern.public java.lang.String getNegativeSuffix()
public void setNegativeSuffix(java.lang.String sNegativeSuffix)
sNegativeSuffix - the new prefix to use for positive numbers. Special
characters like the currency sign '¤', the percent sign '%' and the per
mille sign '‰' are not interpreted nor expanded, as if sNegativeSuffix
was put between quotes in a pattern.public boolean getCurrencyFormat()
public void setCurrencyFormat(boolean swCurrencyFormat)
public int getMultiplier()
setMultiplier(int)public void setMultiplier(int iMultiplier)
Examples: with multiplier 100, 1.23 is formatted as if it where 123, and "123" is parsed as 1.23
iMultiplier - the multiplier to use.java.lang.IllegalArgumentException - if iMultiplier <= 0getMultiplier()public int getGroupingSize()
Grouping size is the number of digits between grouping separators in the integer portion of a number. For example, in the number "1,234,567.89", the grouping size is 3. A value of 0 means that there are no grouping separators (replacing the 'grouping used' setting of DecimalFormat).
setGroupingSize(int),
"java.text.DecimalFormat#getGroupingSeparator"public void setGroupingSize(int iGroupingSize)
java.lang.IllegalArgumentException - if iGroupingSize < 0getGroupingSize(),
"java.text.DecimalFormat#setGroupingSeparator"public int getMaximumIntegerDigits()
setMaximumIntegerDigits(int),
getMinimumIntegerDigits(),
getSignalOverflow()public void setMaximumIntegerDigits(int iMaximumIntegerDigits)
With exponential notation the maximum number of integer digits, if present and not equal to the minumum number of integer digits, specifies the exponent increment. The decimal point is shifted within the formatted number so as to keep the exponent a multiple of the set maximum number of integer digits. The most common use of exponent increments is to generate engineering notation, in which the exponent is a multiple of three.
iMaximumIntegerDigits - the maximum number of integer digits to be shown.java.lang.IllegalArgumentException - if iMaximumIntegerDigits < 0getMaximumIntegerDigits(),
setMinimumIntegerDigits(int),
setSignalOverflow(boolean)public int getMinimumIntegerDigits()
A number with insufficient integer digits will be padded with leading zero padding characters to satisfy the minimum integer digits setting.
setMinimumIntegerDigits(int),
getZeroPaddingChar(),
getMaximumIntegerDigits()public void setMinimumIntegerDigits(int iMinimumIntegerDigits)
For exponential notation with exponent increments (see setExponentIncrement(int) and setMaximumIntegerDigits(int)) the minimum integer digits setting is disregarded while adjusting the exponent value. A number with insufficient integer digits will be padded with leading zero padding characters to satisfy the minimum integer digits setting.
iMinimumIntegerDigits - the minimum number of integer digits to be shown.java.lang.IllegalArgumentException - if iMinimumIntegerDigits < 0getMinimumIntegerDigits(),
setZeroPaddingChar(int),
setMaximumIntegerDigits(int)public boolean getDecimalSeparatorAlwaysShown()
Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
public void setDecimalSeparatorAlwaysShown(boolean swDecimalSeparatorAlwaysShown)
Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
public boolean getParseIntegerOnly()
For example if '.' is the decimal separator and ParseIntegerOnly is true, the string "1234.56" would be parsed as the integer value 1234 and parsing would stop at the '.' character. Of course, the exact format accepted by the parse operation is locale dependant.
setParseIntegerOnly(boolean)public void setParseIntegerOnly(boolean swParseIntegerOnly)
This property can only be set by this method; it can not be set, nor will it be changed, by applying a pattern.
swParseIntegerOnly - true if only the integer part of a number should be parsed,
else false. If true, parsing will stop at the decimal point, and that position will
be indicated as index of the ParsePosition argument to parse().getParseIntegerOnly()public int getMaximumDecimalPlaces()
setMaximumDecimalPlaces(int),
getRetainZeroTail(),
getRoundingMode()public void setMaximumDecimalPlaces(int iMaximumDecimalPlaces)
iMaximumDecimalPlaces - the maximum number of decimal places to be shown.java.lang.IllegalArgumentException - if iMaximumDecimalPlaces < 0getMaximumDecimalPlaces(),
setRetainZeroTail(boolean),
setRoundingMode(int)public int getMinimumDecimalPlaces()
A number with insufficient decimal places will be padded with trailing zero padding characters to satisfy the minimum decimal places setting.
setMinimumDecimalPlaces(int),
getZeroPaddingChar()public void setMinimumDecimalPlaces(int iMinimumDecimalPlaces)
iMinimumDecimalPlaces - the minimum number of decimal places to be shown.java.lang.IllegalArgumentException - if iMinimumDecimalPlaces < 0getMinimumDecimalPlaces(),
setZeroPaddingChar(int)public boolean getRetainZeroTail()
In ArciMath BigDecimal, trailing zeroes in a number are significand. In standard arithmetic trailing zeros of an operation's result are preserved, which best simulates the notation you would use when performing the operation by hand on a piece of paper, except for the division and power operators were indeed this 'natural concept of precision' makes no sense (this is in contrast to binary floating point operations and most electronic calculators, which lose the information about trailing zeros in the fractional part of results). This preservation of trailing zeros is desirable for most calculations (including financial calculations). So, for example:
"1.20" + "1" = "2.20" "1.20" - "1" = "0.20" "1.20" * "1" = "1.20" "1.20" / "1" = "1.20" "1.20" / "2" = "0.60" "1.20" / "10" = "0.12"
setRetainZeroTail(boolean),
getMaximumDecimalPlaces()public void setRetainZeroTail(boolean swRetainZeroTail)
swRetainZeroTail - if true, a pattern like "0.###" will format a number
new be.arci.math.BigDecimal("1.20") as "1.20", if false as "1.2".getRetainZeroTail(),
setMaximumDecimalPlaces(int)public BigDecimal getSmallestModule()
setSmallestModule(be.arci.math.BigDecimal),
getRoundingMode()public void setSmallestModule(BigDecimal bdSmallestModule)
bdSmallestModule - A positive non-zero smallest module, or null
to disable rounding to smallest modules.java.lang.IllegalArgumentException - if bdSmallestModule is negative or zero.getSmallestModule(),
setRoundingMode(int)public int getRoundingMode()
setRoundingMode(int),
getSmallestModule(),
getMaximumDecimalPlaces(),
MathContextpublic void setRoundingMode(int iRoundingMode)
NOTE: Although not documented, DecimalFormat uses the equivalent of MathContext.ROUND_HALF_EVEN for rounding to the maximum number of decimal places, and no rounding (truncation) in other places. By default BigDecimalFormat uses MathContext.ROUND_HALF_UP in calculations.
iRoundingMode - A rounding mode, one of the predefined MathContext.ROUND_xxx
constants.java.lang.IllegalArgumentException - if iRoundingMode
is unrecognized.getRoundingMode(),
setSmallestModule(be.arci.math.BigDecimal),
setMaximumDecimalPlaces(int),
MathContextpublic boolean getExponentialNotation()
setExponentialNotation(boolean),
getMaximumExponentDigits(),
getMinimumExponentDigits(),
getExponentSymbol(),
getExponentSignAlwaysShown()public void setExponentialNotation(boolean swExponentialNotation)
swExponentialNotation - true if this object formats and parses exponentional
notationgetExponentialNotation(),
setMaximumExponentDigits(int),
setMinimumExponentDigits(int),
setExponentSymbol(java.lang.String),
setExponentSignAlwaysShown(boolean)public int getMaximumExponentDigits()
setMaximumExponentDigits(int),
getExponentialNotation(),
getExponentSignAlwaysShown(),
getSignalOverflow()public void setMaximumExponentDigits(int iMaximumExponentDigits)
iMaximumExponentDigits - the maximum number of exponent digits to be shown.java.lang.IllegalArgumentException - if iMaximumExponentDigits < 0getMaximumExponentDigits(),
setExponentialNotation(boolean),
setExponentSignAlwaysShown(boolean),
setSignalOverflow(boolean)public int getMinimumExponentDigits()
If this setting is 0, no exponent (exponent symbol + sign + value) will be shown if the exponent value is zero.
setMinimumExponentDigits(int),
getExponentialNotation(),
getExponentSignAlwaysShown(),
getZeroPaddingChar()public void setMinimumExponentDigits(int iMinimumExponentDigits)
iMinimumExponentDigits - the minimum number of exponent digits that will be shownjava.lang.IllegalArgumentException - if iMinimumExponentDigits < 0getMinimumExponentDigits(),
setExponentialNotation(boolean),
setExponentSignAlwaysShown(boolean),
setZeroPaddingChar(int)public int getExponentIncrement()
setExponentIncrement(int),
getExponentialNotation(),
setMaximumIntegerDigits(int)public void setExponentIncrement(int iExponentIncrement)
iExponentIncrement - The exponent increment. If this value is 0, the exponent
increment is deduced from maximum and minimum integer digits, as in
DecimalFormat: the exponent increment is then taken 0 if
maximum integer digits equals minimum integer digits, and else it is the value
of maximum integer digits itself.java.lang.IllegalArgumentException - if iExponentIncrement < 0getExponentIncrement(),
setExponentialNotation(boolean),
setMaximumIntegerDigits(int)public boolean getExponentSignAlwaysShown()
setExponentSignAlwaysShown(boolean),
getPlusSign(),
getExponentialNotation()public void setExponentSignAlwaysShown(boolean swExponentSignAlwaysShown)
swExponentSignAlwaysShown - true if the exponent is always prefixed with either
the localized minus sign or the localized plus sign, false if only
negative exponents are prefixed with the localized minus sign.getExponentSignAlwaysShown(),
setPlusSign(char),
setExponentialNotation(boolean)public int getZeroPaddingChar()
Are replaced by the zero padding character as non-significant zeroes: leading zeroes in the integer part and the grouping separators enclosed by them, trailing zeroes in the decimal fraction, and leading zeroes in the exponent part, all upto the requested minimum integer digits, minimum decimal places and minimum exponent digits respectively.
setZeroPaddingChar(int),
getMinimumIntegerDigits(),
getMinimumDecimalPlaces(),
getMinimumExponentDigits()public void setZeroPaddingChar(int iZeroPaddingChar)
Are replaced by the zero padding character as non-significant zeroes: leading zeroes in the integer part and the grouping separators enclosed by them, trailing zeroes in the decimal fraction, and leading zeroes in the exponent part, all upto the requested minimum integer digits, minimum decimal places and minimum exponent digits respectively.
This property can only be set by this method; it can not be set, nor will it be changed, by applying a pattern.
iZeroPaddingChar - the character used to replace non-significant zeroes, or
-1 if non-significant zeroes should be retained by format output.java.lang.IllegalArgumentException - if iZeroPaddingChar is not -1 nor a character valuegetZeroPaddingChar(),
setMinimumIntegerDigits(int),
setMinimumDecimalPlaces(int),
setMinimumExponentDigits(int)public char getPaddingChar()
setPaddingChar(char),
getPaddingWidth(),
getPaddingPosition()public void setPaddingChar(char cPaddingChar)
cPaddingChar - the padding charactergetPaddingChar(),
setPaddingWidth(int),
setPaddingPosition(int)public int getPaddingWidth()
setPaddingWidth(int),
getPaddingChar(),
getPaddingPosition(),
getSignalOverflow()public void setPaddingWidth(int iPaddingWidth)
iPaddingWidth - the width to which to pad the formatted numbers with padding characters.
Use the value 0 to disable padding. Use the value -1 to let this BigDecimalFormat
object calculate the padding width as the maximum formatted number width compatible with it's settings.java.lang.IllegalArgumentException - if iPaddingWidth < -1.getPaddingWidth(),
setPaddingChar(char),
setPaddingPosition(int),
setSignalOverflow(boolean)public int getPaddingPosition()
setPaddingPosition(int),
getPaddingWidth(),
getPaddingChar(),
PAD_BEFORE_PREFIX,
PAD_AFTER_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_BEFORE_SUFFIX,
PAD_AFTER_SUFFIXpublic void setPaddingPosition(int iPaddingPosition)
iPaddingPosition - the padding position, one of the predefined PAD_xxx constants.java.lang.IllegalArgumentException - if the padding position is unrecognizedgetPaddingPosition(),
setPaddingWidth(int),
setPaddingChar(char),
PAD_BEFORE_PREFIX,
PAD_AFTER_PREFIX,
PAD_BEFORE_EXPONENT,
PAD_BEFORE_SUFFIX,
PAD_AFTER_SUFFIXpublic int getParsingStrictness()
setParsingStrictness(int),
PARSE_LENIENT,
PARSE_MATCH_PREFIX,
PARSE_MATCH_SUFFIX,
PARSE_MATCH_AFFIXES,
PARSE_MATCH_SIGN_CHARS,
PARSE_MATCH_PADDING_CHAR,
PARSE_MATCH_PADDING_POS,
PARSE_MATCH_PADDING_WIDTH,
PARSE_MATCH_SEPARATOR_CHARS,
PARSE_MATCH_EXPONENT_SYMBOL,
PARSE_MATCH_GROUPING,
PARSE_STRICTpublic void setParsingStrictness(int iParsingStrictness)
iParsingStrictness - a combination ('|' operator) of PARSE_xxx
constants.getParsingStrictness(),
PARSE_LENIENT,
PARSE_MATCH_PREFIX,
PARSE_MATCH_SUFFIX,
PARSE_MATCH_AFFIXES,
PARSE_MATCH_SIGN_CHARS,
PARSE_MATCH_PADDING_CHAR,
PARSE_MATCH_PADDING_POS,
PARSE_MATCH_PADDING_WIDTH,
PARSE_MATCH_SEPARATOR_CHARS,
PARSE_MATCH_EXPONENT_SYMBOL,
PARSE_MATCH_GROUPING,
PARSE_STRICT
|
ArciMath BigDecimal v2.05 now with BigDecimalFormat |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||