Cosmos DB number precision issue when aggregating

21 Views Asked by At

I ran into an issue with a query that was summing up multiple values and returning the sum back to the calling .net application and so have been trying to figure out the right way to go about this. On the surface it looks pretty straightforward and it may be something simple I missed but wanted to ask the community if this would be considered a bug or not.

SELECT (20000 + 15113.95 - 8100 - 11900 - 15113.95) AS total

If I run this in Sql server I get 0 as expected. But if I run the above in Cosmos DB it returns a negative exponential value.

[{“total”: -3.637978807091713e-12}]

The above is just a simplified version of the query (not the actual one). I have tried rounding as well as casting etc but not able to get back 0. I can catch this in .net code and convert to decimal (0) but wondered what other surprises awaits.

0

There are 0 best solutions below