Number and data formatting scenarios
Orientation
Choose one operation instead of treating every formatted number as the same kind of string:
| Task | Focused guide |
|---|---|
| Spell cardinal or ordinal numbers | Numbers in words and ordinals |
| Inflect a noun and combine it with a count | Inflection and quantities |
| Format or parse storage and rates | Byte sizes and rates |
| Format or parse powers of 1000 | Metric numerals |
| Use Roman, compass, multiplier, tuple, or symbol helpers | Specialized formatting utilities |
Example
This verified survey sets English culture and exercises one representative call from several families:
using System.Globalization;
using Humanizer;
using Humanizer.Bytes;
var culture = CultureInfo.GetCultureInfo("en-US");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
AssertEqual("forty-two", 42.ToWords(culture));
AssertEqual("twenty-first", 21.ToOrdinalWords(culture));
AssertEqual("21st", 21.Ordinalize(culture));
AssertEqual("XIV", 14.ToRoman());
AssertEqual("1.5 KB", 1536.Bytes().Humanize("0.0", culture));
AssertEqual("two people", "person".ToQuantity(2, ShowQuantityAs.Words));
AssertEqual("minus one people", "person".ToQuantity(-1, ShowQuantityAs.Words));
Console.WriteLine("forty-two; twenty-first; XIV; 1.5 KB; two people");
static void AssertEqual<T>(T expected, T actual)
{
if (!EqualityComparer<T>.Default.Equals(actual, expected))
throw new InvalidOperationException($"Expected '{expected}', got '{actual}'.");
}
Focused guides separate the typed model, parsing contract, localization behavior, and failure modes. Pass CultureInfo directly where an overload permits it; scope both ambient cultures for APIs without a culture argument.
Pitfall
Do not persist humanized number text as the numeric source of truth. ByteSize uses binary multiples, metric numerals use decimal powers, number-word parsing has locale-specific grammar, and Roman numerals have a strict range. Keep the typed value and choose a parser only for an input format the application explicitly accepts.
Version notes
The survey runs on this 2.x release with byte models from Humanizer.Bytes. Number-word parsing is not available, and only positive 1 selects the singular quantity form.
Related guides and API
- Numbers in words and ordinals
- Byte sizes and rates
- Localization and extensibility
- NumberToWordsExtension API
- OrdinalizeExtensions API
- RomanNumeralExtensions API
- ByteSize API
- ByteSizeExtensions API
- ByteRate API
- MetricNumeralExtensions API
- MetricNumeralFormats API
- HeadingExtensions API
- NumberToNumberExtensions API
- TupleizeExtensions API
- EnglishArticle API