Skip to main content
Version: 3.0.8

Use specialized formatting utilities

Orientation

Humanizer includes a few focused helpers that do not justify forcing a broader string or number abstraction: compass headings and arrows, Roman numerals, readable numeric multipliers, tuple names, localized time-unit symbols, and English article-aware sorting. Use each only when its narrow input contract matches the task.

Example

This executable exercises every utility on fixed input:

Program.cs
using System.Globalization;
using Humanizer;

var culture = CultureInfo.GetCultureInfo("en-US");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;

AssertEqual("southwest", 225d.ToHeading(HeadingStyle.Full, culture));
AssertEqual('↙', 225d.ToHeadingArrow());
AssertEqual("XIV", 14.ToRoman());
AssertEqual(2_000_000, 2.Millions());
AssertEqual("min", TimeUnit.Minute.ToSymbol(culture));
AssertEqual("quadruple", 4.Tupleize());

var titles = new[] { "The Theater", "An Apple", "Bear" };
var sorted = EnglishArticle.PrependArticleSuffix(
EnglishArticle.AppendArticlePrefix(titles));
AssertEqual("An Apple, Bear, The Theater", string.Join(", ", sorted));

Console.WriteLine("southwest; ↙; XIV; 2,000,000; min; quadruple");

static void AssertEqual<T>(T expected, T actual)
{
if (!EqualityComparer<T>.Default.Equals(expected, actual))
throw new InvalidOperationException($"Expected '{expected}', got '{actual}'.");
}

Headings and arrows

ToHeading quantizes a finite, nonnegative degree value to 16 abbreviated or full compass points. ToHeadingArrow uses eight arrows. Normalize negative or otherwise untrusted headings before calling either method. The reverse helpers return a degree value; invalid heading text or arrows return -1.

Roman numerals and readable constants

ToRoman and FromRoman support canonical integers from 1 through 3999. There is no TryFromRoman, so validate external text or handle the thrown exception. Tens, Hundreds, Thousands, Millions, and Billions are arithmetic conveniences for readable numeric constants.

Tuple names and unit symbols

Tupleize emits invariant English names for common counts. ToTuple(culture) is the localized alternative. TimeUnit.ToSymbol(culture) returns locale data; a symbol such as English week is not guaranteed to be one character.

English-only article sorting

EnglishArticle.AppendArticlePrefix moves leading A, An, or The to a suffix and returns the transformed array already sorted. Pass that result directly to PrependArticleSuffix to restore display titles. This advanced helper is deliberately English-only and throws for an empty array.

Pitfall

These APIs are not general parsers. Compass quantization loses the original degree and does not validate or normalize negative, NaN, or infinite input. Roman conversion has a strict range, multiplier methods can overflow their numeric type, and article sorting recognizes only its exact English pattern. Preserve the original value whenever later logic needs it.

Version notes

Most utilities span the documented corpus. Localized time-unit symbols appear in 2.13.14; earlier snapshots need that section removed. Exact locale output is release data, while Roman and invariant tuple examples are stable.