Skip to content

OnixLabs.Numerics.ConversionMode

matthew edited this page May 26, 2026 · 1 revision

ConversionMode Enum

Specifies IEEE 754 binary floating-point conversion modes used when converting float, double, Float128, and Float256 values to BigDecimal or NumberInfo.

Namespace OnixLabs.Numerics
Assembly OnixLabs.Numerics.dll (NuGet)

Definition

public enum ConversionMode

Fields

Name Value Description
Decimal 0 Specifies that IEEE 754 binary floating-point values will be converted from their decimal representation.
Binary 1 Specifies that IEEE 754 binary floating-point values will be converted from their binary representation.

Remarks

IEEE 754 binary floating-point types such as float and double can be interpreted in two distinct ways when converting to a decimal numeric type, and ConversionMode selects between them.

Decimal (default) — The value is converted from its shortest-round-trip decimal string representation. For example, 0.1f converts to exactly 0.1, because "0.1" is the shortest decimal string that round-trips back to that float. This is typically what application code wants, and it matches the decimal value a developer typed in source.

Binary — The value is converted from its exact IEEE 754 binary representation, including any representation error introduced by the binary encoding. For example, 0.1f converts to approximately 0.100000001490116119384765625, because that is the exact rational value stored in the 32-bit float. Use this mode when you need the mathematically exact stored value, for example in numerical analysis or when comparing bit-identical representations.

ConversionMode is consumed by the following overloads in NumericsExtensions:

  • ToBigDecimal(this float, ConversionMode)
  • ToBigDecimal(this double, ConversionMode)
  • ToNumberInfo(this float, ConversionMode)
  • ToNumberInfo(this double, ConversionMode)
  • ToNumberInfo(this Float128, ConversionMode)
  • ToNumberInfo(this Float256, ConversionMode)

The default value of ConversionMode is Decimal (field value 0), so calling any of these overloads without specifying a mode selects the decimal interpretation.

See Also

ONIXLabs .NET Library


Clone this wiki locally