NumberFormat
ConsoleMonster.Widgets
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
- The elapsed time.
- shortForm bool = false
- 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
- 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
- The count to display.
- singular string
- The noun used for exactly one.
- plural string
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- The time left.
Returns
string The text.