Getting Started
HumanNumbers is a formatting pipeline that ensures every number your application emits is immediately understandable to humans. It centralizes numeric presentation into a single, culture-aware system integrated throughout the ASP.NET Core stack.
Installation
# Core Library
dotnet add package HumanNumbers
# ASP.NET Core Integration
dotnet add package HumanNumbers.AspNetCore
Quick Start
Start formatting numbers with just a few lines of code:
using HumanNumbers;
// Basic number formatting
1500000m.ToHuman(); // "1.5M"
1500000m.ToHumanCurrency(); // "$1.5M"
// Extension methods for all numeric types
(48000).ToHuman(); // "48K"
Request Culture Resolution
HumanNumbers integrates directly with ASP.NET Core localization features to format numbers dynamically according to the requester's culture:
Resolution Precedence Order
- Explicit Context Override: Looks for a culture set inside HttpContext Items using the
CultureResolverhelper. - Request Localization Middleware: Resolves using standard ASP.NET Core
IRequestCultureFeature(based on cookies, query strings, orAccept-Languageheaders). - Thread Default: Falls back to
CultureInfo.CurrentCulture.
Setting Explicit Culture Manually
To manually enforce a specific culture on a per-request basis (e.g., depending on a customer's database setting or custom token), use the CultureResolver.SetCulture method in your controllers or middleware:
// Enforce French localization on the active HttpContext for the current request
CultureResolver.SetCulture(HttpContext, new CultureInfo("fr-FR"));