Units.NET adds typed quantities and unit conversions to C# projects via NuGet. It reduces magic constants by binding values to unit enums and supporting parse, format, and arithmetic.
Overview
Units.NET is a .NET library that represents physical quantities as strongly typed structures instead of raw doubles with ambiguous units. Developers construct values with unit-specific factories or enums, convert with properties or helpers, and pass quantity types through APIs to avoid mixing incompatible measures.
Operator overloads allow arithmetic and derived quantities such as speed from length and time. Localization follows thread culture for abbreviations and number formatting, with parse and try-parse helpers for user-facing input. Runtime classes including Quantity, UnitConverter, UnitParser, and related info types support dynamic unit pickers and converters in applications.
Custom units can be registered at runtime for domain-specific measures while reusing parsing and conversion infrastructure. Serialization to JSON, XML, and other formats is documented on the project wiki. Precision is intentionally oriented toward convenience: conversions route through per-quantity base units with documented acceptable error bounds for most units.
The package ships on NuGet for modern .NET and .NET Standard targets, with optional extension packages for number syntax on newer C# versions. Parallel implementations exist for other languages based on the same unit definitions. Sample WPF projects demonstrate dynamic unit converter UIs and binding converters.
Key features
- Strongly typed quantity structs
- Large built-in unit catalog
- Parse and try-parse from strings
- Culture-aware abbreviations
- Operator overloads for physics math
- Runtime quantity and unit metadata
- Custom unit extension support
- JSON and XML serialization guides
Use cases
- Engineering apps with unit-safe math
- Dynamic unit converter desktop tools
- APIs accepting localized unit strings
- Sensor data with mixed measures
- Avoiding ambiguous unit constants