pub struct Number { /* private fields */ }Expand description
An exact decimal and, once a numeric handler resolved it, its resolved options and its display form. Opaque: the digit backend is internal (owner decision 1).
Implementations§
Source§impl Number
impl Number
Sourcepub fn parse(number_literal: &str) -> Option<Number>
pub fn parse(number_literal: &str) -> Option<Number>
A number-literal; None if s is not one (or is past the
implementation limits: 40 significant digits, exponent ±9999).
Sourcepub fn from_f64(x: f64, host: &dyn Host) -> Option<Number>
pub fn from_f64(x: f64, host: &dyn Host) -> Option<Number>
The finite x (the shortest decimal that round-trips it, through
the host); None for NaN and infinities.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Whether the value is negative (-0 included).
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Whether the value is an integer.
Sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
The value as an i64, when it is an integer below 10^18 in magnitude.
Sourcepub fn write_plain(&self, out: &mut dyn Sink)
pub fn write_plain(&self, out: &mut dyn Sink)
Writes the exact value in plain neutral digits: -1234.5, 0.001,
-0 — no exponent, no rounding.
Sourcepub fn resolve(
spec: NumberSpec,
cx: &FnContext<'_>,
operand: Option<&Value<'_>>,
options: &Options<'_, '_>,
errs: &mut dyn ErrorSink,
) -> Option<Number>
pub fn resolve( spec: NumberSpec, cx: &FnContext<'_>, operand: Option<&Value<'_>>, options: &Options<'_, '_>, errs: &mut dyn ErrorSink, ) -> Option<Number>
Resolves an expression under spec, as :number does
(number.md): the operand rules, the options of spec’s function
(any other option is ignored), inheritance from a number or measure
operand, the digit plan and rounding. None: a fallback value, the
reason reported through errs.
Sourcepub fn digits(&self) -> Option<Digits<'_>>
pub fn digits(&self) -> Option<Digits<'_>>
The rounded digits to display; None for a number no handler
resolved — and, with feature intl on wasm32-unknown-unknown
([crate::INTL_NUMBERS]), always: the host rounds and formats
(Number::format_by_host).
Sourcepub fn exact_digits(&self) -> Digits<'_>
pub fn exact_digits(&self) -> Digits<'_>
The exact value’s digits, unrounded — how an unannotated number
formats (plans/03-runtime.md §2.6): -1234.5, 0.001, -0.
Sourcepub fn grouping(&self) -> Option<Grouping>
pub fn grouping(&self) -> Option<Grouping>
The resolved useGrouping; None when it is not set (or the number
is bare).
Sourcepub fn is_selectable(&self) -> bool
pub fn is_selectable(&self) -> bool
Whether a numeric handler resolved this number and it may select (formatting.md, “Resolve Selectors”).
Sourcepub fn matches(
&self,
cx: &FnContext<'_>,
key: &str,
errs: &mut dyn ErrorSink,
) -> bool
pub fn matches( &self, cx: &FnContext<'_>, key: &str, errs: &mut dyn ErrorSink, ) -> bool
Match(self, key) for numeric selectors (number.md, “Number
Selection”): exact numeric keys, then the plural or ordinal category
of the formatted digits; Bad Variant Key for any other key.
Sourcepub fn better_than(key1: &str, key2: &str) -> bool
pub fn better_than(key1: &str, key2: &str) -> bool
BetterThan(key1, key2) for two matching keys: an exact (numeric)
key beats a keyword.