Class BtcAutoFormat
- All Implemented Interfaces:
Serializable
,Cloneable
This class, a concrete extension of BtcFormat
, is distinguished by its
accommodation of multiple denominational units as follows:
When formatting Bitcoin monetary values, an instance of this class automatically adjusts the denominational units in which it represents a given value so as to minimize the number of consecutive zeros in the number that is displayed, and includes either a currency code or symbol in the formatted value to indicate which denomination was chosen.
When parsing String
representations of Bitcoin monetary values, instances of
this class automatically recognize units indicators consisting of currency codes and
symbols, including including those containing currency or metric prefixes such as
"ยข"
or "c"
to indicate hundredths, and interpret each number being
parsed in accordance with the recognized denominational units.
A more detailed explanation, including examples, is in the documentation for the BtcFormat
class, and further information beyond that is in the documentation for the Format
class, from which this class descends.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum for specifying the style of currency indicators that are used when formatting, either codes or symbols.Nested classes/interfaces inherited from class org.bitcoinj.utils.BtcFormat
BtcFormat.Builder
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
Fields inherited from class org.bitcoinj.utils.BtcFormat
COIN_SCALE, COIN_SYMBOL_ALT, decimalGroups, MICROCOIN_SCALE, MILLICOIN_SCALE, minimumFractionDigits, numberFormat
-
Constructor Summary
ModifierConstructorDescriptionprotected
BtcAutoFormat
(Locale locale, BtcAutoFormat.Style style, int fractionPlaces) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if the other instance is equivalent to this one.int
Return the number of decimal places in the fraction part of numbers formatted by this instance.protected int
scale()
Returns theint
value indicating coin denomination.protected int
scale
(BigInteger satoshis, int fractionPlaces) Calculate the appropriate denomination for the given Bitcoin monetary value.toString()
Return a brief description of this formatter.Methods inherited from class org.bitcoinj.utils.BtcFormat
builder, coinCode, coinSymbol, format, format, format, formatToCharacterIterator, getAvailableLocales, getCodeInstance, getCodeInstance, getCodeInstance, getCodeInstance, getCoinInstance, getCoinInstance, getCoinInstance, getCoinInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getMicroInstance, getMicroInstance, getMicroInstance, getMicroInstance, getMilliInstance, getMilliInstance, getMilliInstance, getMilliInstance, getSymbolInstance, getSymbolInstance, getSymbolInstance, getSymbolInstance, hashCode, negify, parse, parse, parseObject, pattern, prefixCode, prefixSymbol, prefixUnitsIndicator, symbols
Methods inherited from class java.text.Format
clone, format, parseObject
-
Constructor Details
-
BtcAutoFormat
Constructor
-
-
Method Details
-
scale
Calculate the appropriate denomination for the given Bitcoin monetary value. This method takes a BigInteger representing a quantity of satoshis, and returns the number of places that value's decimal point is to be moved when formatting said value in order that the resulting number represents the correct quantity of denominational units.As a side-effect, this sets the units indicators of the underlying NumberFormat object. Only invoke this from a synchronized method, and be sure to put the DecimalFormatSymbols back to its proper state, otherwise immutability, equals() and hashCode() fail.
- Specified by:
scale
in classBtcFormat
- Parameters:
satoshis
- The number of satoshis having the value for which the shift is calculatedfractionPlaces
- The number of decimal places available for displaying the fractional part of the denominated value- Returns:
- The size of the shift in increasingly-precise decimal places
-
scale
protected int scale()Returns theint
value indicating coin denomination. This is what causes the number in a parsed value that lacks a units indicator to be interpreted as a quantity of bitcoins. -
fractionPlaces
public int fractionPlaces()Return the number of decimal places in the fraction part of numbers formatted by this instance. This is the maximum number of fraction places that will be displayed; the actual number used is limited to a precision of satoshis. -
equals
Return true if the other instance is equivalent to this one. Formatters for different locales will never be equal, even if they behave identically. -
toString
Return a brief description of this formatter. The exact details of the representation are unspecified and subject to change, but will include some representation of the pattern and the number of fractional decimal places.
-