Added in API level 30

FractionPrecision


abstract class FractionPrecision : Precision
kotlin.Any
   ↳ android.icu.number.Precision
   ↳ android.icu.number.FractionPrecision

A class that defines a rounding strategy based on a number of fraction places and optionally significant digits to be used when formatting numbers in NumberFormatter.

To create a FractionPrecision, use one of the factory methods on Precision.

Summary

Public methods
open Precision!
withMaxDigits(maxSignificantDigits: Int)

Ensure that no more than this number of significant digits are retained when rounding according to fraction rules.

open Precision!
withMinDigits(minSignificantDigits: Int)

Ensure that no less than this number of significant digits are retained when rounding according to fraction rules.

open Precision!
withSignificantDigits(minSignificantDigits: Int, maxSignificantDigits: Int, priority: NumberFormatter.RoundingPriority!)

Override maximum fraction digits with maximum significant digits depending on the magnitude of the number.

Inherited functions

Public methods

withMaxDigits

Added in API level 30
open fun withMaxDigits(maxSignificantDigits: Int): Precision!

Ensure that no more than this number of significant digits are retained when rounding according to fraction rules.

For example, with integer rounding, the number 123.4 becomes "123". However, with maximum figures set to 2, 123.4 becomes "120" instead.

This setting does not affect the number of trailing zeros. For example, with fixed fraction of 2, 123.4 would become "120.00".

This is equivalent to withSignificantDigits(1, maxSignificantDigits, STRICT).

Parameters
maxSignificantDigits Int: Round the number to no more than this number of significant figures.
Return
Precision! A Precision for chaining or passing to the NumberFormatter rounding() setter.
Exceptions
java.lang.IllegalArgumentException if the input number is too big or smaller than 1.

withMinDigits

Added in API level 30
open fun withMinDigits(minSignificantDigits: Int): Precision!

Ensure that no less than this number of significant digits are retained when rounding according to fraction rules.

For example, with integer rounding, the number 3.141 becomes "3". However, with minimum figures set to 2, 3.141 becomes "3.1" instead.

This setting does not affect the number of trailing zeros. For example, 3.01 would print as "3", not "3.0".

This is equivalent to withSignificantDigits(1, minSignificantDigits, RELAXED).

Parameters
minSignificantDigits Int: The number of significant figures to guarantee.
Return
Precision! A Precision for chaining or passing to the NumberFormatter rounding() setter.
Exceptions
java.lang.IllegalArgumentException if the input number is too big or smaller than 1.

withSignificantDigits

Added in API level 34
open fun withSignificantDigits(
    minSignificantDigits: Int,
    maxSignificantDigits: Int,
    priority: NumberFormatter.RoundingPriority!
): Precision!

Override maximum fraction digits with maximum significant digits depending on the magnitude of the number. See UNumberRoundingPriority.

Parameters
minSignificantDigits Int: Pad trailing zeros to achieve this minimum number of significant digits.
maxSignificantDigits Int: Round the number to achieve this maximum number of significant digits.
priority NumberFormatter.RoundingPriority!: How to disambiguate between fraction digits and significant digits.
Return
Precision! A precision for chaining or passing to the NumberFormatter precision() setter.