Class 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 the Format class, from which this class descends.

    See Also:
    Format, NumberFormat, DecimalFormat, DecimalFormatSymbols, Coin, Serialized Form
    • 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 class BtcFormat
        Parameters:
        satoshis - The number of satoshis having the value for which the shift is calculated
        fractionPlaces - 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 the int 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.
        Specified by:
        scale in class BtcFormat
      • 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.
        Overrides:
        equals in class BtcFormat
      • 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 class java.lang.Object