高效地将OracleDecimal转换为带有截断的.NET十进制 [英] Efficiently Converting OracleDecimal to .NET decimal w/truncation

查看:152
本文介绍了高效地将OracleDecimal转换为带有截断的.NET十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用(decimal) OracleUdt.GetValue()

MDSYS.SDO_GEOMETRY(2001, 1041001, 
  MDSYS.SDO_POINT_TYPE(-2.89957214912471,1.56043985049899E-15,NULL),NULL,NULL)

根据 Oracle文档,这很可能是由于以下原因之一:十进制值超出.NET的28十进制精度范围.在我们的数据库中,超出此精度限制的数据极为罕见,并且转换必须尽可能高效.

According to Oracle documentation, this is likely because one of the decimal values exceeds .NET's precision range of 28 decimals. Data that exceeds this precision limit in our database is extremely rare, and conversion needs to be as efficient as possible.

在超出最大精度的情况下,通过适当地截断结果来处理此异常的最佳选择是什么?

What is the best option for handling this exception by gracefully truncating the result if it exceeds the maximum precision?

推荐答案

参考@AndrewR的答案,请考虑以下测试:

With reference to @AndrewR's answer, consider the following test:

    [Test, Explicit]
    public void OracleDecimal_NarrowingConversion_ShouldSucceed()
    {
        string sigfigs = "-9236717.7113439267890123456789012345678";
        OracleDecimal od = new OracleDecimal(sigfigs);
        OracleDecimal narrowedOd = OracleDecimal.SetPrecision(od, 28); //fails
        //OracleDecimal narrowedOd = OracleDecimal.SetPrecision(od, 27); //succeeds
        object narrowedObjectValue = (object)narrowedOd.Value;
        Assert.IsInstanceOf<decimal>(narrowedObjectValue);
    }

12c提供程序的Oracle文档指出精度应在1到38之间.(

The Oracle documentation for the 12c Providers states that the precision should be between 1 and 38. (http://docs.oracle.com/cd/E51173_01/win.122/e17732/OracleDecimalStructure.htm#i1003600) . The .Net 'decimal' docs say that the precision is to 28 - 29 sig figs. I don't know why 28 doesn't work in this case.

编辑:如果删除-"符号,则以上内容适用于28个有效数字.

Edit: If you remove the '-' sign, the above works at 28 significant figures.

这篇关于高效地将OracleDecimal转换为带有截断的.NET十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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