Skip to main content
Version: 4.0 (next)

Humanizer.ToQuantityExtensions

ToQuantityExtensions Class​

Provides extensions for formatting a System.String word as a quantity.

public static class ToQuantityExtensions

Inheritance System.Object → ToQuantityExtensions

Methods​

ToQuantityExtensions.ToQuantity(this string, double) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, double quantity);
Parameters​

input System.String

The word to be prefixed

quantity System.Double

The quantity of the word

Returns​

System.String

Example​

"request".ToQuantity(0.2) => "0.2 requests"

ToQuantityExtensions.ToQuantity(this string, double, string, IFormatProvider) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, double quantity, string? format=null, System.IFormatProvider? formatProvider=null);
Parameters​

input System.String

The word to be prefixed

quantity System.Double

The quantity of the word

format System.String

A standard or custom numeric format string.

formatProvider System.IFormatProvider

An object that supplies culture-specific formatting information.

Returns​

System.String

Example​

"request".ToQuantity(0.2) => "0.2 requests" "request".ToQuantity(10.6, format: "N0") => "10.6 requests" "request".ToQuantity(1.0, format: "N0") => "1 request"

ToQuantityExtensions.ToQuantity(this string, int, ShowQuantityAs) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, int quantity, Humanizer.ShowQuantityAs showQuantityAs=Humanizer.ShowQuantityAs.Numeric);
Parameters​

input System.String

The word to be prefixed

quantity System.Int32

The quantity of the word

showQuantityAs ShowQuantityAs

How to show the quantity. Numeric by default

Returns​

System.String

Example​

"request".ToQuantity(0) => "0 requests" "request".ToQuantity(1) => "1 request" "request".ToQuantity(2) => "2 requests" "men".ToQuantity(2) => "2 men" "process".ToQuantity(1200, ShowQuantityAs.Words) => "one thousand two hundred processes"

ToQuantityExtensions.ToQuantity(this string, int, string, IFormatProvider) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, int quantity, string? format, System.IFormatProvider? formatProvider=null);
Parameters​

input System.String

The word to be prefixed

quantity System.Int32

The quantity of the word

format System.String

A standard or custom numeric format string.

formatProvider System.IFormatProvider

An object that supplies culture-specific formatting information.

Returns​

System.String

Example​

"request".ToQuantity(0) => "0 requests" "request".ToQuantity(10000, format: "N0") => "10,000 requests" "request".ToQuantity(1, format: "N0") => "1 request"

ToQuantityExtensions.ToQuantity(this string, long, ShowQuantityAs) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, long quantity, Humanizer.ShowQuantityAs showQuantityAs=Humanizer.ShowQuantityAs.Numeric);
Parameters​

input System.String

The word to be prefixed

quantity System.Int64

The quantity of the word

showQuantityAs ShowQuantityAs

How to show the quantity. Numeric by default

Returns​

System.String

Example​

"request".ToQuantity(0) => "0 requests" "request".ToQuantity(1) => "1 request" "request".ToQuantity(2) => "2 requests" "men".ToQuantity(2) => "2 men" "process".ToQuantity(1200, ShowQuantityAs.Words) => "one thousand two hundred processes"

ToQuantityExtensions.ToQuantity(this string, long, string, IFormatProvider) Method​

Prefixes the provided word with the number and accordingly pluralizes or singularizes the word

public static string ToQuantity(this string input, long quantity, string? format, System.IFormatProvider? formatProvider=null);
Parameters​

input System.String

The word to be prefixed

quantity System.Int64

The quantity of the word

format System.String

A standard or custom numeric format string.

formatProvider System.IFormatProvider

An object that supplies culture-specific formatting information.

Returns​

System.String

Example​

"request".ToQuantity(0) => "0 requests" "request".ToQuantity(10000, format: "N0") => "10,000 requests" "request".ToQuantity(1, format: "N0") => "1 request"