pub struct NumberFormat { /* private fields */ }Expand description
A parsed number format code. Cheap to clone.
Implementations§
Source§impl NumberFormat
impl NumberFormat
Sourcepub fn parse(code: &str) -> NumberFormat
pub fn parse(code: &str) -> NumberFormat
Parses a format code. Never fails: unknown or malformed parts degrade to literal text, and
a code longer than MAX_FORMAT_CODE_CHARS characters degrades to General.
pub fn general() -> NumberFormat
pub fn code(&self) -> &str
pub fn is_general(&self) -> bool
Sourcepub fn date_shape(&self, value: f64) -> Option<(bool, bool)>
pub fn date_shape(&self, value: f64) -> Option<(bool, bool)>
For a date or time format, whether the section that formats value shows calendar parts (year, month,
day) and whether it shows time parts, as (date, time). None for any other format and for
elapsed-time codes like [h]:mm, whose value is a duration, not a moment.
pub fn is_percent(&self) -> bool
Sourcepub fn kind(&self) -> FormatKind
pub fn kind(&self) -> FormatKind
Best guess at the format category for the ribbon’s dropdown.
Sourcepub fn round_as_displayed(&self, n: f64) -> f64
pub fn round_as_displayed(&self, n: f64) -> f64
The number n as this format displays it: what Excel stores when “Set precision as
displayed” is on. Fixed decimals, percent, thousands scaling (0.0,,), scientific and
fraction sections round to what they show; the section is picked as for display, so
0.00;(0.0) keeps one decimal for negatives. Observed in Excel (COM,
Workbook.PrecisionAsDisplayed), these keep the full value: General, date and time
formats (mm:ss.0 included), text formats and sections without digits ("x", ;;;).
The section is picked by NumberFormat::rounding_section, which ignores conditions.
Never returns -0.
Source§impl NumberFormat
impl NumberFormat
Sourcepub fn parse_cached(code: &str) -> NumberFormat
pub fn parse_cached(code: &str) -> NumberFormat
Like NumberFormat::parse, but remembers recently parsed codes (per thread, bounded) so
formatting many values with one code parses it once. Same result as parse.
Trait Implementations§
Source§impl Clone for NumberFormat
impl Clone for NumberFormat
Source§fn clone(&self) -> NumberFormat
fn clone(&self) -> NumberFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more