public class FormattedDecimal extends Object
Modifier and Type | Field and Description |
---|---|
int |
formatOptions
Use LocaleFormat.OPTION_XXX values here.
|
StringBuilder |
formattedNumber
Place the String to parse here, or when the number is formatted, it
is placed here.
|
StringBuilder |
fractionalPart
When building a decimal value, put the part after the decimal point
here.
|
StringBuilder |
integerPart
When building a decimal value, put the part before the decimal point
here.
|
boolean |
isNegative
If the value you are formatting is negative, set this true.
|
boolean |
isStrict
By default FormattedDecimal is lenient during parsing, ignoring the placement of
currency marks and positive/negative signs.
|
Constructor and Description |
---|
FormattedDecimal() |
Modifier and Type | Method and Description |
---|---|
FormattedDecimal |
applyFormat(DecimalFormat format)
Call this before doing a format() but after setting the integer/fractional
parts.
|
FormattedDecimal |
applyFormat(String format)
Call this before doing a format() but after setting the integer/fractional
parts.
|
void |
cache()
Place a FormattedDecimal Object retrieved from getCached() back into
the Cache.
|
void |
clear()
Clear all fields.
|
FormattedDecimal |
format(DecimalSymbols symbols)
Format this integerPart and fractionalPart of this FormattedDecimal and place
it into formattedNumber.
|
static String |
format(DecimalSymbols ds,
String integerPart,
String fractionalPart,
boolean isNegative,
LocaleFormat optionalFormat,
int optionsToSet,
int optionsToClear) |
static FormattedDecimal |
getCached()
Get a FormattedDecimal Object from the Cache.
|
long |
modifyOptions(int optionsToSet,
int optionsToClear)
Modify specified option bits.
|
FormattedDecimal |
optionsFromLocale(LocaleFormat lf)
Set the useCurrencySymbol and useGrouping values based
on the options from the specified LocaleFormat.
|
FormattedDecimal |
parse(DecimalSymbols ds)
Parse the String in formattedNumber and separate it into its integer
and fractional parts, convert them to English digits,
and place them in integerPart and fractionalPart
respectively.
|
FormattedDecimal |
reformatAfterParse()
After a successful parse operation, this will rebuild the parsed
String into formattedNumber as a plain English digit decimal number
with an optional negative sign at the front (if negative) followed by
the integer part, the decimal point and the fractional part.
|
void |
restoreOptions(long fromModifyOptions)
Restore option bits changed by modifyOptions.
|
FormattedDecimal |
set(String integerPart,
String fractionalPart,
boolean isNegative,
boolean showCurrencySymbol,
boolean showGroupings)
A convenience method to set some of the values.
|
long |
setOption(int optionsToSetOrClear,
boolean setOrClear)
Set or clear option bits depending on the value of setOrClear.
|
FormattedDecimal |
setStrict(boolean strict)
Sets the isStrict value and returns this FormattedDecimal.
|
public StringBuilder integerPart
public StringBuilder fractionalPart
public boolean isNegative
public int formatOptions
public StringBuilder formattedNumber
public boolean isStrict
public FormattedDecimal setStrict(boolean strict)
strict
- the value to set to isStrict.public void clear()
public static FormattedDecimal getCached()
public void cache()
public FormattedDecimal set(String integerPart, String fractionalPart, boolean isNegative, boolean showCurrencySymbol, boolean showGroupings)
integerPart
- fractionalPart
- isNegative
- showCurrencySymbol
- showGroupings
- public FormattedDecimal format(DecimalSymbols symbols)
symbols
- the DecimalSymbols to use for formatting.public FormattedDecimal parse(DecimalSymbols ds) throws NumberFormatException
ds
- The DecimalSymbols to use for parsing.NumberFormatException
public static String format(DecimalSymbols ds, String integerPart, String fractionalPart, boolean isNegative, LocaleFormat optionalFormat, int optionsToSet, int optionsToClear)
public FormattedDecimal reformatAfterParse()
The resulting String can be parsed by BigDecimal or any standard simple decimal conversion.
public FormattedDecimal optionsFromLocale(LocaleFormat lf)
lf
- the LocaleFormatpublic long modifyOptions(int optionsToSet, int optionsToClear)
optionsToSet
- the option bits to set.optionsToClear
- the option bits to clear.public void restoreOptions(long fromModifyOptions)
fromModifyOptions
- the value returned from the modifyOptions()
call that modified the options.public long setOption(int optionsToSetOrClear, boolean setOrClear)
optionToSetOrClear
- the bits to set or clear.setOrClear
- true to set the bits, false to clear them.public FormattedDecimal applyFormat(String format)
f
- the format String in the form "##00.00##". A '0' indicates
that a digit must be placed there. A '#' indicates that if the digit
value there is insignificant it may be left out. The total number
before or after the decimal point indicate the maximum number of allowed
digits for that portion.
A ',' in the format indicates that Thousand groupings should be used.
A '$' indicates that currency symbol should be shown.public FormattedDecimal applyFormat(DecimalFormat format)