Class NumberFormatterSettings<T extends NumberFormatterSettings<?>>

    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      T decimal​(NumberFormatter.DecimalSeparatorDisplay style)
      Sets the decimal separator display strategy.
      boolean equals​(java.lang.Object other)
      T grouping​(NumberFormatter.GroupingStrategy strategy)
      Specifies the grouping strategy to use when formatting numbers.
      int hashCode()
      T integerWidth​(IntegerWidth style)
      Specifies the minimum and maximum number of digits to render before the decimal mark.
      T macros​(com.ibm.icu.impl.number.MacroProps macros)
      Deprecated.
      ICU 60 This API is ICU internal only.
      T notation​(Notation notation)
      Specifies the notation style (simple, scientific, or compact) for rendering numbers.
      T padding​(com.ibm.icu.impl.number.Padder padder)
      Deprecated.
      ICU 60 This API is ICU internal only.
      T perUnit​(MeasureUnit perUnit)
      Sets a unit to be used in the denominator.
      T precision​(Precision precision)
      Specifies the rounding precision to use when formatting numbers.
      T rounding​(Precision rounder)
      Deprecated.
      ICU 62 Use precision() instead.
      T roundingMode​(java.math.RoundingMode roundingMode)
      Specifies how to determine the direction to round a number when it has more digits than fit in the desired precision.
      T scale​(Scale scale)
      Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
      T sign​(NumberFormatter.SignDisplay style)
      Sets the plus/minus sign display strategy.
      T symbols​(DecimalFormatSymbols symbols)
      Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers.
      T symbols​(NumberingSystem ns)
      Specifies that the given numbering system should be used when fetching symbols.
      T threshold​(java.lang.Long threshold)
      Deprecated.
      ICU 60 This API is ICU internal only.
      java.lang.String toSkeleton()
      Creates a skeleton string representation of this number formatter.
      T unit​(MeasureUnit unit)
      Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
      T unitWidth​(NumberFormatter.UnitWidth style)
      Sets the width of the unit (measure unit or currency).
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • notation

        public T notation​(Notation notation)
        Specifies the notation style (simple, scientific, or compact) for rendering numbers.
        • Simple notation: "12,300"
        • Scientific notation: "1.23E4"
        • Compact notation: "12K"

        All notation styles will be properly localized with locale data, and all notation styles are compatible with units, rounding strategies, and other number formatter settings.

        Pass this method the return value of a Notation factory method. For example:

         NumberFormatter.with().notation(Notation.compactShort())
         
        The default is to use simple notation.
        Parameters:
        notation - The notation strategy to use.
        Returns:
        The fluent chain.
        See Also:
        Notation
      • unit

        public T unit​(MeasureUnit unit)
        Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
        • Unit of measure: "12.3 meters"
        • Currency: "$12.30"
        • Percent: "12.3%"

        Note: The unit can also be specified by passing a Measure to LocalizedNumberFormatter.format(Measure). Units specified via the format method take precedence over units specified here. This setter is designed for situations when the unit is constant for the duration of the number formatting process.

        All units will be properly localized with locale data, and all units are compatible with notation styles, rounding strategies, and other number formatter settings.

        Pass this method any instance of MeasureUnit. For units of measure:

         NumberFormatter.with().unit(MeasureUnit.METER)
         
        Currency:
         NumberFormatter.with().unit(Currency.getInstance("USD"))
         
        Percent:
         NumberFormatter.with().unit(NoUnit.PERCENT)
         

        See perUnit(com.ibm.icu.util.MeasureUnit) for information on how to format strings like "5 meters per second".

        The default is to render without units (equivalent to NoUnit.BASE).

        Parameters:
        unit - The unit to render.
        Returns:
        The fluent chain.
        See Also:
        MeasureUnit, Currency, NoUnit, perUnit(com.ibm.icu.util.MeasureUnit)
      • perUnit

        public T perUnit​(MeasureUnit perUnit)
        Sets a unit to be used in the denominator. For example, to format "3 m/s", pass METER to the unit and SECOND to the perUnit.

        Pass this method any instance of MeasureUnit. For example:

         NumberFormatter.with().unit(MeasureUnit.METER).perUnit(MeasureUnit.SECOND)
         

        The default is not to display any unit in the denominator.

        If a per-unit is specified without a primary unit via unit(com.ibm.icu.util.MeasureUnit), the behavior is undefined.

        Parameters:
        perUnit - The unit to render in the denominator.
        Returns:
        The fluent chain
        See Also:
        unit(com.ibm.icu.util.MeasureUnit)
      • precision

        public T precision​(Precision precision)
        Specifies the rounding precision to use when formatting numbers.
        • Round to 3 decimal places: "3.142"
        • Round to 3 significant figures: "3.14"
        • Round to the closest nickel: "3.15"
        • Do not perform rounding: "3.1415926..."

        Pass this method the return value of one of the factory methods on Precision. For example:

         NumberFormatter.with().precision(Precision.fixedFraction(2))
         

        In most cases, the default rounding precision is to round to 6 fraction places; i.e., Precision.maxFraction(6). The exceptions are if compact notation is being used, then the compact notation rounding precision is used (see Notation.compactShort() for details), or if the unit is a currency, then standard currency rounding is used, which varies from currency to currency (see Precision.currency(com.ibm.icu.util.Currency.CurrencyUsage) for details).

        Parameters:
        precision - The rounding precision to use.
        Returns:
        The fluent chain.
        See Also:
        Precision
      • rounding

        @Deprecated
        public T rounding​(Precision rounder)
        Deprecated.
        ICU 62 Use precision() instead. This method is for backwards compatibility and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
      • roundingMode

        public T roundingMode​(java.math.RoundingMode roundingMode)
        Specifies how to determine the direction to round a number when it has more digits than fit in the desired precision. When formatting 1.235:
        • Ceiling rounding mode with integer precision: "2"
        • Half-down rounding mode with 2 fixed fraction digits: "1.23"
        • Half-up rounding mode with 2 fixed fraction digits: "1.24"
        The default is HALF_EVEN. For more information on rounding mode, see the ICU userguide here: http://userguide.icu-project.org/formatparse/numbers/rounding-modes
        Parameters:
        roundingMode - The rounding mode to use.
        Returns:
        The fluent chain.
        See Also:
        Precision
      • grouping

        public T grouping​(NumberFormatter.GroupingStrategy strategy)
        Specifies the grouping strategy to use when formatting numbers.
        • Default grouping: "12,300" and "1,230"
        • Grouping with at least 2 digits: "12,300" and "1230"
        • No grouping: "12300" and "1230"

        The exact grouping widths will be chosen based on the locale.

        Pass this method an element from the NumberFormatter.GroupingStrategy enum. For example:

         NumberFormatter.with().grouping(GroupingStrategy.MIN2)
         
        The default is to perform grouping according to locale data; most locales, but not all locales, enable it by default.
        Parameters:
        strategy - The grouping strategy to use.
        Returns:
        The fluent chain.
        See Also:
        NumberFormatter.GroupingStrategy
      • integerWidth

        public T integerWidth​(IntegerWidth style)
        Specifies the minimum and maximum number of digits to render before the decimal mark.
        • Zero minimum integer digits: ".08"
        • One minimum integer digit: "0.08"
        • Two minimum integer digits: "00.08"

        Pass this method the return value of IntegerWidth.zeroFillTo(int). For example:

         NumberFormatter.with().integerWidth(IntegerWidth.zeroFillTo(2))
         
        The default is to have one minimum integer digit.
        Parameters:
        style - The integer width to use.
        Returns:
        The fluent chain.
        See Also:
        IntegerWidth
      • symbols

        public T symbols​(DecimalFormatSymbols symbols)
        Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers.
        • en_US symbols: "12,345.67"
        • fr_FR symbols: "12 345,67"
        • de_CH symbols: "12’345.67"
        • my_MY symbols: "၁၂,၃၄၅.၆၇"

        Pass this method an instance of DecimalFormatSymbols. For example:

         NumberFormatter.with().symbols(DecimalFormatSymbols.getInstance(new ULocale("de_CH")))
         

        Note: DecimalFormatSymbols automatically chooses the best numbering system based on the locale. In the examples above, the first three are using the Latin numbering system, and the fourth is using the Myanmar numbering system.

        Note: The instance of DecimalFormatSymbols will be copied: changes made to the symbols object after passing it into the fluent chain will not be seen.

        Note: Calling this method will override the NumberingSystem previously specified in symbols(NumberingSystem).

        The default is to choose the symbols based on the locale specified in the fluent chain.

        Parameters:
        symbols - The DecimalFormatSymbols to use.
        Returns:
        The fluent chain.
        See Also:
        DecimalFormatSymbols
      • symbols

        public T symbols​(NumberingSystem ns)
        Specifies that the given numbering system should be used when fetching symbols.
        • Latin numbering system: "12,345"
        • Myanmar numbering system: "၁၂,၃၄၅"
        • Math Sans Bold numbering system: "𝟭𝟮,𝟯𝟰𝟱"

        Pass this method an instance of NumberingSystem. For example, to force the locale to always use the Latin alphabet numbering system (ASCII digits):

         NumberFormatter.with().symbols(NumberingSystem.LATIN)
         

        Note: Calling this method will override the DecimalFormatSymbols previously specified in symbols(DecimalFormatSymbols).

        The default is to choose the best numbering system for the locale.

        Parameters:
        ns - The NumberingSystem to use.
        Returns:
        The fluent chain.
        See Also:
        NumberingSystem
      • unitWidth

        public T unitWidth​(NumberFormatter.UnitWidth style)
        Sets the width of the unit (measure unit or currency). Most common values:
        • Short: "$12.00", "12 m"
        • ISO Code: "USD 12.00"
        • Full name: "12.00 US dollars", "12 meters"

        Pass an element from the NumberFormatter.UnitWidth enum to this setter. For example:

         NumberFormatter.with().unitWidth(UnitWidth.FULL_NAME)
         

        The default is the SHORT width.

        Parameters:
        style - The width to use when rendering numbers.
        Returns:
        The fluent chain
        See Also:
        NumberFormatter.UnitWidth
      • sign

        public T sign​(NumberFormatter.SignDisplay style)
        Sets the plus/minus sign display strategy. Most common values:
        • Auto: "123", "-123"
        • Always: "+123", "-123"
        • Accounting: "$123", "($123)"

        Pass an element from the NumberFormatter.SignDisplay enum to this setter. For example:

         NumberFormatter.with().sign(SignDisplay.ALWAYS)
         

        The default is AUTO sign display.

        Parameters:
        style - The sign display strategy to use when rendering numbers.
        Returns:
        The fluent chain
        See Also:
        NumberFormatter.SignDisplay
      • decimal

        public T decimal​(NumberFormatter.DecimalSeparatorDisplay style)
        Sets the decimal separator display strategy. This affects integer numbers with no fraction part. Most common values:
        • Auto: "1"
        • Always: "1."

        Pass an element from the NumberFormatter.DecimalSeparatorDisplay enum to this setter. For example:

         NumberFormatter.with().decimal(DecimalSeparatorDisplay.ALWAYS)
         

        The default is AUTO decimal separator display.

        Parameters:
        style - The decimal separator display strategy to use when rendering numbers.
        Returns:
        The fluent chain
        See Also:
        NumberFormatter.DecimalSeparatorDisplay
      • scale

        public T scale​(Scale scale)
        Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting. Most common values:
        • Multiply by 100: useful for percentages.
        • Multiply by an arbitrary value: useful for unit conversions.

        Pass an element from a Scale factory method to this setter. For example:

         NumberFormatter.with().scale(Scale.powerOfTen(2))
         

        The default is to not apply any multiplier.

        Parameters:
        scale - An amount to be multiplied against numbers before formatting.
        Returns:
        The fluent chain
        See Also:
        Scale
      • macros

        @Deprecated
        public T macros​(com.ibm.icu.impl.number.MacroProps macros)
        Deprecated.
        ICU 60 This API is ICU internal only.
        Internal method to set a starting macros.
      • padding

        @Deprecated
        public T padding​(com.ibm.icu.impl.number.Padder padder)
        Deprecated.
        ICU 60 This API is ICU internal only.
        Set the padding strategy. May be added to ICU 61; see #13338.
      • threshold

        @Deprecated
        public T threshold​(java.lang.Long threshold)
        Deprecated.
        ICU 60 This API is ICU internal only.
        Internal fluent setter to support a custom regulation threshold. A threshold of 1 causes the data structures to be built right away. A threshold of 0 prevents the data structures from being built.
      • toSkeleton

        public java.lang.String toSkeleton()
        Creates a skeleton string representation of this number formatter. A skeleton string is a locale-agnostic serialized form of a number formatter.

        Not all options are capable of being represented in the skeleton string; for example, a DecimalFormatSymbols object. If any such option is encountered, an UnsupportedOperationException is thrown.

        The returned skeleton is in normalized form, such that two number formatters with equivalent behavior should produce the same skeleton.

        Returns:
        A number skeleton string with behavior corresponding to this number formatter.
        Throws:
        java.lang.UnsupportedOperationException - If the number formatter has an option that cannot be represented in a skeleton string.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object