Skip to content

Decimal number representation for monetary amounts #144

Open
@donmendelson

Description

@donmendelson

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:

  • Are the IEEE-754:2008 decimal standards suitable for SBE?
  • Does even decimal128 support sufficient precision, or is arbitrary precision a requirement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions