Class BtcAutoFormat
- java.lang.Object
-
- java.text.Format
-
- org.bitcoinj.utils.BtcFormat
-
- org.bitcoinj.utils.BtcAutoFormat
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public final class BtcAutoFormat extends BtcFormat
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 theFormat
class, from which this class descends.- See Also:
Format
,NumberFormat
,DecimalFormat
,DecimalFormatSymbols
,Coin
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BtcAutoFormat.Style
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
-
-
Field Summary
-
Fields inherited from class org.bitcoinj.utils.BtcFormat
COIN_SCALE, COIN_SYMBOL_ALT, decimalGroups, MICROCOIN_SCALE, MILLICOIN_SCALE, minimumFractionDigits, numberFormat
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BtcAutoFormat(java.util.Locale locale, BtcAutoFormat.Style style, int fractionPlaces)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
Return true if the other instance is equivalent to this one.int
fractionPlaces()
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(java.math.BigInteger satoshis, int fractionPlaces)
Calculate the appropriate denomination for the given Bitcoin monetary value.java.lang.String
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
-
-
-
-
Constructor Detail
-
BtcAutoFormat
protected BtcAutoFormat(java.util.Locale locale, BtcAutoFormat.Style style, int fractionPlaces)
Constructor
-
-
Method Detail
-
scale
protected int scale(java.math.BigInteger satoshis, int fractionPlaces)
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
public boolean equals(java.lang.Object o)
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
public java.lang.String 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.- Overrides:
toString
in classjava.lang.Object
-
-