Oracle number to C# decimal

有些话、适合烂在心里 提交于 2019-11-28 13:26:49

I just had a similar issue, and tried the approach of changing the OracleDataAdapter to return Oracle specific types ( data_adapter.ReturnProviderSpecificTypes = true; ), but this is just a PITA, you end up casting OracleStrings back to strings, etc.

In the end I solved it by doing the precision rounding in the SQL statement using Oracle's round function:

SELECT round( myfield, 18 ) FROM mytable

Dotnet will then happily convert the figure to a decimal.

OracleDecimal has a larger precision than decimal. For that reason, you have to reduce the precision first. Forget all the parsing, use implicit conversion. Try something along the lines of (untested):

decimal d = (decimal)(OracleDecimal.SetPrecision(oraReader.GetOracleDecimal(0), 28));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!