Skip to content
ConsoleMonster
Class

NumberFormat

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Modifiers
static

Compact, invariant formatting for numbers, percentages and durations used across widgets.

Inheritance

  • object
  • NumberFormat

Methods

public static string Clock(TimeSpan elapsed, bool shortForm = false) #

Formats a clock: 00:01:23 (or 01:23 under an hour when shortForm is true).

Parameters

elapsed System.TimeSpan required
The elapsed time.
shortForm bool = false optional
Whether to drop the hours when zero.

Returns

string The text.
public static string Compact(double value) #

Formats a count compactly: 950, 1.2k, 12k, 1.4M. NaN and infinities give "-".

Parameters

value double required
The value.

Returns

string The text.
public static string CountPhrase(long count, string singular, string plural) #

Formats an invariant count with the caller's singular or plural noun. No language rules or suffixes are inferred.

Parameters

count long required
The count to display.
singular string required
The noun used for exactly one.
plural string required
The noun used for other counts.

Returns

string The count, a space and the selected noun.
public static string Duration(TimeSpan duration) #

Formats a duration compactly: 850ms, 12.4s, 1m 12s, 1h 02m.

Parameters

duration System.TimeSpan required
The duration.

Returns

string The text.
public static string Grouped(double value) #

Formats a number with thousands separators: 12,345. NaN and infinities give "-".

Parameters

value double required
The value.

Returns

string The text.
public static bool IsFinite(double value) #

Whether a value is a real number (not NaN or an infinity).

Parameters

value double required
The value.

Returns

bool True when finite.
public static string Missing(GlyphTier tier) #

The text for a number that has no meaningful display (NaN, infinity): an em dash, or "-" in the ASCII tier.

Parameters

tier ConsoleMonster.Capabilities.GlyphTier required
The glyph tier.

Returns

string The dash.
public static string Percent(double fraction) #

Formats a fraction (0-1) as a whole percentage: 64%. A share above zero but under 1% reads <1%.

Parameters

fraction double required
The fraction.

Returns

string The text.
public static double PositiveOrZero(double value) #

The value when it is finite and positive, otherwise 0 (for scales, totals and segment widths).

Parameters

value double required
The value.

Returns

double The usable magnitude.
public static string Remaining(TimeSpan remaining) #

A time left, rounded up: 12s under a minute, otherwise as NumberFormat.Duration (3m 05s).

Parameters

remaining System.TimeSpan required
The time left.

Returns

string The text.