Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DocumentDB Decimal Truncation

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.

like image 291
lgrabarevic Avatar asked Apr 10 '15 11:04

lgrabarevic


People also ask

Is Cosmos DB a DocumentDB?

CosmosDB is the new DocumentDB for NoSQL solution. The Azure Cosmos DB DocumentDB API or SQL (DocumentDB) API is now known as Azure Cosmos DB SQL API. You don't need to change anything to continue running your apps built with DocumentDB/DocumentDB API.

What is the maximum document you can insert read replace in a collection?

The maximum size of a document today is 2MB.

What is_ Ts in Cosmos DB?

August 5, 2021. Cosmos DB automactially adds a timestamp field called “_ts”. everytime a document is created or updated.

What is Atom record sequence?

Atoms consist of a small set of primitive types e.g. string, bool, number etc., records are structs and sequences are arrays consisting of atoms, records or sequences. The database engine of Azure Cosmos DB is capable of efficiently translating and projecting the data models onto the ARS based data model.


1 Answers

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.

like image 173
Aravind Krishna R. Avatar answered Sep 21 '22 17:09

Aravind Krishna R.