azure-cosmosdbazure-cosmosdb-sqlapi

Issue saving 0.0 to cosmosdb double to int


Using cosmosdb as storage I ran into an issue. I saved an object where one of the properties was set to 0.0 (tried both using double, decimal and float). When the value was later retrieved it was 0 and not with the precision 0.0. If I set it to something like 0.1 or 2.1 everything works as I would expect it to work.

Can someone explain why this is happening? For the usage of my data, I need it to be 0.0.

Best regards


Solution

  • I can imagine this being an optimization of CosmosDB, since 0 == 0.0 as far as the value goes.

    It feels like you're trying to force formatting, probably for display purposes, into your data-store. If you always format your data the way you want to display it, it doesn't matter if the value is 0, 0.0 or 0.316692.