A .NET library providing strongly typed units of measurement for safer and more readable code.
Units.NET is a .NET library that provides strongly typed units of measurement, such as Length, Mass, and Speed, to help developers write safer and more readable code. It solves the problem of unit confusion and magic constants by enforcing type safety and offering built-in conversion between hundreds of units.
.NET developers working with physical quantities in scientific, engineering, IoT, or any domain requiring precise unit handling and conversions.
Developers choose Units.NET for its comprehensive unit coverage, strong typing that prevents runtime errors, and ease of use with features like operator overloading and localization, making it a robust alternative to manual unit management.
Makes life working with units of measurement just a little bit better.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Includes hundreds of units across various quantities like Length, Mass, and Speed, with support for custom extensions, as shown in the extensive unit definitions and dynamic runtime enumeration.
Uces types like Length and Mass instead of raw numbers, preventing unit confusion and compile-time errors, evidenced by examples where passing Mass to a Force parameter causes compilation failures.
Allows intuitive arithmetic operations on quantities, such as Speed * Time = Length, making code more readable and reducing manual conversion errors, as demonstrated in the operator overloads section.
Provides culture-specific abbreviations and number formats for internationalization, with examples using en-US and ru-RU cultures to format and parse quantities seamlessly.
Conversions have inherent errors up to 1E-5 for most units due to double-precision base units, as admitted in the 'Precision and Accuracy' section, which may not meet high-accuracy requirements.
Some units share abbreviations (e.g., 'pt' for DtpPoint and PrinterPoint), causing AmbiguousUnitParseException and forcing developers to implement custom parsers, as highlighted in the 'Gotcha' section.
Adding custom units requires runtime configuration and mapping, which can be verbose and error-prone, as shown in the custom units examples with manual conversion function definitions.