Contains extension methods for changing a number to Metric representation (ToMetric) and from Metric representation back to the number (FromMetric)
public static class MetricNumeralExtensionsInheritance System.Object → MetricNumeralExtensions
Converts a Metric representation into a number.
public static double FromMetric(this string input);input System.String
Metric representation to convert to a number
System.Double
A number after a conversion from a Metric representation.
"1k".FromMetric() => 1000d
"123".FromMetric() => 123d
"100m".FromMetric() => 1E-1We don't support input in the format {number}{name} nor {number} {name}. We only provide a solution for {number}{symbol} and {number} {symbol}.
Converts a number into a valid and Human-readable Metric representation.
public static string ToMetric(this double input, System.Nullable<Humanizer.MetricNumeralFormats> formats=null, System.Nullable<int> decimals=null);input System.Double
Number to convert to a Metric representation.
formats System.Nullable<MetricNumeralFormats>
A bitwise combination of MetricNumeralFormats enumeration values that format the metric representation.
decimals System.Nullable<System.Int32>
The maximum number of fractional digits to include. When KeepTrailingZeros is used, exactly this many fractional digits are included. If null, all available precision is preserved and the flag has no effect.
System.String
A valid Metric representation
1000d.ToMetric() => "1k"
123d.ToMetric() => "123"
1E-1.ToMetric() => "100m"Inspired by a snippet from Thom Smith. See <a href="http://stackoverflow\.com/questions/12181024/formatting\-a\-number\-with\-a\-metric\-prefix"\>this link</a> for more.
Converts a number into a valid and Human-readable Metric representation.
public static string ToMetric(this int input, System.Nullable<Humanizer.MetricNumeralFormats> formats=null, System.Nullable<int> decimals=null);input System.Int32
Number to convert to a Metric representation.
formats System.Nullable<MetricNumeralFormats>
A bitwise combination of MetricNumeralFormats enumeration values that format the metric representation.
decimals System.Nullable<System.Int32>
The maximum number of fractional digits to include. When KeepTrailingZeros is used, exactly this many fractional digits are included. If null, all available precision is preserved and the flag has no effect.
System.String
A valid Metric representation
1000.ToMetric() => "1k"
123.ToMetric() => "123"
1E-1.ToMetric() => "100m"Inspired by a snippet from Thom Smith. See <a href="http://stackoverflow\.com/questions/12181024/formatting\-a\-number\-with\-a\-metric\-prefix"\>this link</a> for more.
Converts a number into a valid and Human-readable Metric representation.
public static string ToMetric(this long input, System.Nullable<Humanizer.MetricNumeralFormats> formats=null, System.Nullable<int> decimals=null);input System.Int64
Number to convert to a Metric representation.
formats System.Nullable<MetricNumeralFormats>
A bitwise combination of MetricNumeralFormats enumeration values that format the metric representation.
decimals System.Nullable<System.Int32>
The maximum number of fractional digits to include. When KeepTrailingZeros is used, exactly this many fractional digits are included. If null, all available precision is preserved and the flag has no effect.
System.String
A valid Metric representation
1000.ToMetric() => "1k"
123.ToMetric() => "123"
1E-1.ToMetric() => "100m"Inspired by a snippet from Thom Smith. See <a href="http://stackoverflow\.com/questions/12181024/formatting\-a\-number\-with\-a\-metric\-prefix"\>this link</a> for more.