• Version 1.16.0
Show / Hide Table of Contents

Manipulating Real Numbers

Double Conversion

Except for special cases, FIX field values are text-based, so the regular presentation of real numbers with a decimal point is used, for example:

... 35=x|268=3|...|270=9462.50|271=5 ...

The interface of the Message class offers a few overloads, allowing users to set/get field values of native language types like int, long and double. The field value set/get members convert the value of a primitive type into/from its text presentation.

However, for native types like float and double, there is no unambiguous transformation available because double values usually have no finite presentation due to the limitation of the data type.

For example:

const double Price = 100.10;

The variable value will be 100.099999999999998, not 100.1, because each double value is expressed as X * 2 ^ Y, where X is mantissa and Y is 2-basis exponent.

As a result, there could be accuracy issues.

Using Decimal Instead of double

In contrast to the double type, Decimal presents real numbers using 10-basis exponent. In other words, each decimal number is expressed as X * 10 ^ Y, where X is mantissa and Y is an exponent.

Parsing Decimal from the text presentation is also free of approximation issues in bounds of values, used in FIX messages.

In this article
Back to top Copyright © Onix Solutions.
Generated by DocFX