#[non_exhaustive]pub enum Number {
Int(i128),
Float(f64),
Decimal {
mantissa: i128,
scale: u32,
},
}Expand description
A number as a cell reads it: an integer and a decimal stay exact, a float is rounded when spelled.
Equality compares the representation, not the amount: Decimal { mantissa: 1250, scale: 2 }
differs from Decimal { mantissa: 125, scale: 1 }, and Int(12) from
Decimal { mantissa: 12, scale: 0 }.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Int(i128)
Any integer type, widened.
Float(f64)
f32 or f64.
Decimal
mantissa / 10^scale, exactly: a decimal type’s value. Spelled with fewer digits than
scale, it rounds half to even, as a float’s spelling does.
Implementations§
Source§impl Number
impl Number
Sourcepub fn format(value: impl Numeric, decimals: u8) -> String
pub fn format(value: impl Numeric, decimals: u8) -> String
Spell value with decimals digits after the point and its thousands grouped, in
English, or an empty string when it holds none.
use tablo_core::Number;
assert_eq!(Number::format(1234.5, 2), "1,234.50");
assert_eq!(Number::format(-3, 0), "-3");Sourcepub fn format_in(cx: &Cx, value: impl Numeric, decimals: u8) -> String
pub fn format_in(cx: &Cx, value: impl Numeric, decimals: u8) -> String
Spell value as format does, with the separators of the request’s
locale: 1 234,50 in French.
Sourcepub fn percent(value: impl Numeric, decimals: u8) -> String
pub fn percent(value: impl Numeric, decimals: u8) -> String
Spell value, a percentage such as 12.5 for twelve and a half percent, with
decimals digits, in English, or an empty string when it holds none.
use tablo_core::Number;
assert_eq!(Number::percent(12.5, 1), "12.5%");
assert_eq!(Number::percent(-1250, 0), "-1,250%");