Skip to content

Precision

Andreas Larsen edited this page Nov 6, 2013 · 3 revisions

Precision of Conversions and Representations

Units.NET was not designed for high-precision, but rather a tool of convenience and simplicity. As a result, there is usually a small error involved in both representing a value of a unit and converting between units.

This is a design decision and I am open to improvements, but basically it goes something like this:

  • A base unit is chosen for all classes of units, which is represented by a double value (64-bit).
  • As an example, for length, area and volume these are meters, m² and m³ respectively. I have typically chosen the base SI units where possible.
  • A design decision was made to let all conversions go via the base unit, because that simplified the implementation a great deal.
  • As a result, any conversion and even round-trip conversions (to a different unit and back) do come with an error, and the error is larger for units that are way larger or way smaller than the base unit.
  • In the unit tests I accept an error less than 1E-5 for all units I've added so far. In many usecases this is sufficient, but for some usecases this is definitely not OK.
Clone this wiki locally