FIXTradingCommunity / fix-simple-binary-encoding

A FIX standard for binary message encoding
Other
262 stars 69 forks source link

Decimal number representation for monetary amounts #144

Open donmendelson opened 2 years ago

donmendelson commented 2 years ago

Monetary amounts and prices are mostly exact decimal numbers. It is well documented that monetary amounts are poorly represented by binary single- and double-precision floating-point numbers that programmers are familiar with. This problem has a long and dreary history. C language and its descendants were originally developed for engineering problems such as telephone switches, not for financial applications. The languages that support decimal types often treat them as a class rather than as a primitive type. Due to poor and non-standard representations of decimal numbers in programming languages, we made a decision for SBE v1.0 to use a composite type of mantissa + exponent.

I would like to revisit that decision for SBE 2.x and am soliciting opinions on it. One of the drivers for reconsideration is digital tokens that may have exact decimals with high precision.

As a matter of fact, the IEEE-754:2008 standard does have representations of exact decimal floating-point numbers, along with the familiar binaries. It defines decimal32, decimal64, and decimal128 types. Recent versions of C and C++ have bindings to those types, but many other languages do not. Some may have accessibility through libraries.

Questions: