Decimal truncation of Azure DocumentDB

I am currently using Azure DocumentDB to store pricing product data. Almost everything works fine, but now I have a problem that my decimal numbers (System.Decimal) are truncated when reading from DocumentDB.
For example, this price:

  Input Price: 25.1132356547854257645454

will be truncated to

  DocumentDB Price: 25.113235654785

Since we use the synchronization mechanism to search for price changes, this will lead to a price change, since this is not the same price.
I do not know how I can change the behavior of DocumentDB. In the worst case scenario, I would have to cut my starting prices to prevent this problem, but I would prefer not to.

Thanks for the help.

+6
source share
1 answer

Azure DocumentDB uses the IEEE JSON floating point number. This requires data to be portable across different programming platforms and applications. Unfortunately, this can truncate large integers or decimal numbers with higher precision, as you can see.

To get around this, consider breaking the number into two part numbers, presenting as a string if you are using only for equality or maintaining a truncated representation.

Hope this helps.

+6
source

Source: https://habr.com/ru/post/984945/


All Articles