Skip to main content
Version: 4.0 (next)

Humanizer.NumberToWordsExtension

NumberToWordsExtension Class

Converts numbers to localized words and ordinals. The output is culture-aware, including locale-specific high-range scale names and English-family differences such as en, en-GB, and en-IN.

public static class NumberToWordsExtension

Inheritance System.Object → NumberToWordsExtension

Methods

NumberToWordsExtension.ToIndianWords(this int, IndianScaleStyle) Method

Converts the given value to Indian English cardinal words using the selected large-number vocabulary.

public static string ToIndianWords(this int number, Humanizer.IndianScaleStyle scaleStyle=Humanizer.IndianScaleStyle.NamedScales);

Parameters

number System.Int32

The value to convert.

scaleStyle IndianScaleStyle

The Indian large-number vocabulary to use.

Returns

System.String
The Indian English cardinal words for number.

Exceptions

System.ArgumentOutOfRangeException
scaleStyle is not a defined value.

NumberToWordsExtension.ToIndianWords(this long, IndianScaleStyle) Method

Converts the given value to Indian English cardinal words using the selected large-number vocabulary.

public static string ToIndianWords(this long number, Humanizer.IndianScaleStyle scaleStyle=Humanizer.IndianScaleStyle.NamedScales);

Parameters

number System.Int64

The value to convert.

scaleStyle IndianScaleStyle

The Indian large-number vocabulary to use.

Returns

System.String
The Indian English cardinal words for number.

Exceptions

System.ArgumentOutOfRangeException
scaleStyle is not a defined value.

Remarks

NamedScales uses the named-scale vocabulary of the en-IN culture. CroreBased uses common crore-based expressions without changing the configured converter or the behavior of other locales.

NumberToWordsExtension.ToOrdinalWords(this int, GrammaticalGender, WordForm, CultureInfo) Method

Converts a number to ordinal words supporting locale's specific variations.

public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to ordinal words

gender GrammaticalGender

The grammatical gender to use for output words

wordForm WordForm

Form of the word, i.e. abbreviation

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The number converted into ordinal words

Example

In Spanish:

3.ToOrdinalWords(GrammaticalGender.Masculine, WordForm.Normal) -> "tercero"
3.ToOrdinalWords(GrammaticalGender.Masculine, WordForm.Abbreviation) -> "tercer"
3.ToOrdinalWords(GrammaticalGender.Feminine, WordForm.Normal) -> "tercera"
3.ToOrdinalWords(GrammaticalGender.Feminine, WordForm.Abbreviation) -> "tercera"

NumberToWordsExtension.ToOrdinalWords(this int, GrammaticalGender, CultureInfo) Method

for Brazilian Portuguese locale 1.ToOrdinalWords(GrammaticalGender.Masculine) -> "primeiro" 1.ToOrdinalWords(GrammaticalGender.Feminine) -> "primeira"

public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to words

gender GrammaticalGender

The grammatical gender to use for output words

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String

NumberToWordsExtension.ToOrdinalWords(this int, WordForm, CultureInfo) Method

Converts a number to ordinal words supporting locale's specific variations.

public static string ToOrdinalWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to ordinal words

wordForm WordForm

Form of the word, i.e. abbreviation

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The number converted into ordinal words

Example

In Spanish:

1.ToOrdinalWords(WordForm.Normal) -> "primero" // As in "He llegado el primero".
3.ToOrdinalWords(WordForm.Abbreviation) -> "tercer" // As in "Vivo en el tercer piso"

NumberToWordsExtension.ToOrdinalWords(this int, CultureInfo) Method

1.ToOrdinalWords() -> "first"

public static string ToOrdinalWords(this int number, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to ordinal words

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String

NumberToWordsExtension.ToTuple(this int, CultureInfo) Method

1.ToTuple() -> "single"

public static string ToTuple(this int number, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to tuple

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String

NumberToWordsExtension.ToWords(this int, bool, WordForm, CultureInfo) Method

Converts the given value to localized cardinal words with an explicit conjunction choice and requested word form.

public static string ToWords(this int number, bool addAnd, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

The value to convert.

addAnd System.Boolean

Whether to include the culture's conjunction before the terminal group.

wordForm WordForm

The requested word form.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

Example

In Spanish, numbers ended in 1 changes its form depending on their position in the sentence.

21.ToWords(WordForm.Normal) -> veintiuno // as in "Mi número favorito es el veintiuno".
21.ToWords(WordForm.Abbreviation) -> veintiún // as in "En total, conté veintiún coches"

NumberToWordsExtension.ToWords(this int, bool, CultureInfo) Method

Converts the given value to localized cardinal words with an explicit conjunction choice.

public static string ToWords(this int number, bool addAnd, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

The value to convert.

addAnd System.Boolean

Whether to include the culture's conjunction before the terminal group.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

NumberToWordsExtension.ToWords(this int, GrammaticalGender, CultureInfo) Method

Converts the given value to localized cardinal words using grammatical gender where supported.

public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

The value to convert.

gender GrammaticalGender

The grammatical gender to use when the locale supports gendered forms.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

Example

Russian:

1.ToWords(GrammaticalGender.Masculine) -> "один"
1.ToWords(GrammaticalGender.Feminine) -> "одна"

Hebrew:

1.ToWords(GrammaticalGender.Masculine) -> "אחד"
1.ToWords(GrammaticalGender.Feminine) -> "אחת"

NumberToWordsExtension.ToWords(this int, WordForm, GrammaticalGender, CultureInfo) Method

Converts the given value to localized cardinal words using both word form and grammatical gender.

public static string ToWords(this int number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

The value to convert.

wordForm WordForm

The requested word form.

gender GrammaticalGender

The grammatical gender to use when the locale supports gendered forms.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

Example

In Spanish, numbers ended in 1 change its form depending on their position in the sentence.

21.ToWords(WordForm.Normal, GrammaticalGender.Masculine) -> veintiuno // as in "Mi número favorito es el veintiuno".
21.ToWords(WordForm.Abbreviation, GrammaticalGender.Masculine) -> veintiún // as in "En total, conté veintiún coches"
21.ToWords(WordForm.Normal, GrammaticalGender.Feminine) -> veintiuna // as in "veintiuna personas"

NumberToWordsExtension.ToWords(this int, WordForm, CultureInfo) Method

Converts the given value to localized cardinal words using both word form and grammatical gender.

public static string ToWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

Number to be turned to words

wordForm WordForm

Form of the word, i.e. abbreviation

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The number converted to words

Example

In Spanish, numbers ended in 1 change its form depending on their position in the sentence.

21.ToWords(WordForm.Normal) -> veintiuno // as in "Mi número favorito es el veintiuno".
21.ToWords(WordForm.Abbreviation) -> veintiún // as in "En total, conté veintiún coches"

NumberToWordsExtension.ToWords(this int, CultureInfo) Method

Converts the given value to localized cardinal words.

public static string ToWords(this int number, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int32

The value to convert.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

NumberToWordsExtension.ToWords(this long, GrammaticalGender, CultureInfo) Method

Converts the given value to localized cardinal words using grammatical gender where supported.

public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int64

The value to convert.

gender GrammaticalGender

The grammatical gender to use when the locale supports gendered forms.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

Example

Russian:

1.ToWords(GrammaticalGender.Masculine) -> "один"
1.ToWords(GrammaticalGender.Feminine) -> "одна"

Hebrew:

1.ToWords(GrammaticalGender.Masculine) -> "אחד"
1.ToWords(GrammaticalGender.Feminine) -> "אחת"

NumberToWordsExtension.ToWords(this long, WordForm, GrammaticalGender, CultureInfo) Method

Converts the given value to localized cardinal words using both word form and grammatical gender.

public static string ToWords(this long number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture=null);

Parameters

number System.Int64

The value to convert.

wordForm WordForm

The requested word form.

gender GrammaticalGender

The grammatical gender to use when the locale supports gendered forms.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

Returns

System.String
The localized cardinal words for number.

Example

In Spanish, numbers ended in 1 changes its form depending on their position in the sentence.

21.ToWords(WordForm.Normal, GrammaticalGender.Masculine) -> veintiuno // as in "Mi número favorito es el veintiuno".
21.ToWords(WordForm.Abbreviation, GrammaticalGender.Masculine) -> veintiún // as in "En total, conté veintiún coches"
21.ToWords(WordForm.Normal, GrammaticalGender.Feminine) -> veintiuna // as in "veintiuna personas"

NumberToWordsExtension.ToWords(this long, WordForm, CultureInfo, bool) Method

Converts the given value to localized cardinal words using the requested word form.

public static string ToWords(this long number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture=null, bool addAnd=false);

Parameters

number System.Int64

The value to convert.

wordForm WordForm

The requested word form.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

addAnd System.Boolean

Whether to include the culture's conjunction before the terminal group.

Returns

System.String
The localized cardinal words for number.

Example

In Spanish, numbers ended in 1 changes its form depending on their position in the sentence.

21.ToWords(WordForm.Normal) -> veintiuno // as in "Mi número favorito es el veintiuno".
21.ToWords(WordForm.Abbreviation) -> veintiún // as in "En total, conté veintiún coches"

NumberToWordsExtension.ToWords(this long, CultureInfo, bool) Method

Converts the given value to localized cardinal words using the culture's default conjunction policy.

public static string ToWords(this long number, System.Globalization.CultureInfo? culture=null, bool addAnd=true);

Parameters

number System.Int64

The value to convert.

culture System.Globalization.CultureInfo

The culture to use. If null, the current culture is used.

addAnd System.Boolean

Whether to include the culture's conjunction before the terminal group.

Returns

System.String
The localized cardinal words for number.