FIX Messaging | Table of Content | Message Validation |

OnixS .NET FIX Engine, version 4.8.0.0

Manipulating real numbers |

This topic depicts issues, related to using real numbers while manipulating FIX messages, as well as solutions for the issues, are offered by the FIX Engine.

Double Transformation Issues

FIX Protocol supposes FIX messages that exchange using 'tag=value' presentation. Except for special cases, the field value is a text-based, so regular presentation of real numbers with a decimal point is used: 35=x|268=3|..|270=9462.50|271=5

The interface of the Message class that encapsulates primary operations over FIX fields for a FIX message, 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 function-member converts the value of a primitive type into/from its string presentation using natural transformation.

However, for native types like float and double, there's no unambiguous transformation available. That's because double values usually have no finite presentation due to the limitation of the data type. In particular, assume the following initialization of a variable of double type is executed:

C#

const double Price = 100.10;

Using Decimal Instead of double

In contrast to a double type, Decimal presents real numbers use 10-basis exponent. Therefore, each number looks like 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, operated in FIX messages. Thus, operating prices and quantities as Decimal, instead of double types, eliminate issues that are caused by an inexact value presentation, as well as gives performance benefits.