7
votes

I'm currently using the Azure DocumentDB to store product data with prices. Nearly everything is working quite fine but now I have the issue that my decimals (System.Decimal) are being truncated when reading from DocumentDB.
For example this price:

Input Price: 25.1132356547854257645454

will be truncated into

DocumentDB Price: 25.113235654785

As we are using a sync mechanism to find price changes, this will result into a price change as it is not the same price anymore.
I have no idea how I can change the behavior of the DocumentDB. In worst case I would have to truncate my input prices to prevent this problem, but I would rather not.

Thanks for help.

1

1 Answers

7
votes

Azure DocumentDB uses IEEE floating point numbers per the JSON standard. This is required so that the data is portable across different programming platforms and applications. Unfortunately, this can lead to the truncation of large integers or higher precision decimal numbers like you're seeing.

To work around this, please consider breaking up the number to a two part number, representing as a string if you're only using for equality, or storing the truncated representation.

Hope this helps.