Skip to main content
Version: 2.10.1

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, and English article-aware sorting. Use each only when its narrow input contract matches the task.

Example​

This executable exercises every utility available in this release 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("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; 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​

Tupleize emits invariant English names for common counts. ToTuple(culture) is the localized alternative. Time-unit symbols are not available in this release.

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. Humanizer 2 also retains its historical sub-namespaces.