Azure DocumentDB十进制截断 [英] Azure DocumentDB Decimal Truncation

查看:56
本文介绍了Azure DocumentDB十进制截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Azure DocumentDB存储带有价格的产品数据.几乎一切工作都很好,但是现在我有一个问题,当从DocumentDB读取数据时,我的小数点(System.Decimal)被截断了.
例如此价格:

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

将被截断为


DocumentDB Price: 25.113235654785

由于我们使用同步机制来查找价格变化,因此将导致价格变化,因为它不再是相同的价格了.
我不知道如何更改DocumentDB的行为.在最坏的情况下,我必须截断我的投入品价格以防止出现此问题,但我宁愿不这样做.

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.

感谢您的帮助.

推荐答案

Azure DocumentDB使用 IEEE浮点数 JSON标准.这是必需的,以便数据可以在不同的编程平台和应用程序之间移植.不幸的是,这可能会导致大整数或更高精度的十进制数字被截断,如您所见.

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.

希望这会有所帮助.

这篇关于Azure DocumentDB十进制截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆