Skip to main content
Version: 3.0.8

Number and data formatting scenarios

Orientation

Choose one operation instead of treating every formatted number as the same kind of string:

TaskFocused guide
Spell cardinal or ordinal numbersNumbers in words and ordinals
Parse a localized number phraseParse number words
Inflect a noun and combine it with a countInflection and quantities
Format or parse storage and ratesByte sizes and rates
Format or parse powers of 1000Metric numerals
Use Roman, compass, multiplier, tuple, or symbol helpersSpecialized formatting utilities

Example

This verified survey sets English culture and exercises one representative call from several families:

Program.cs
using System.Globalization;
using Humanizer;

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));

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’s available calls compile and run against the selected package. Number-word parsing begins in 3.0.1 and changes from int to long on main/preview. Culture-aware byte-rate formatting begins in 2.13.14. Historical snapshots remove or replace unavailable focused pages.