Truncation in OracleNumber.Parse()

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
JuliaH
Posts: 1
Joined: Wed 20 Oct 2021 15:28

Truncation in OracleNumber.Parse()

Post by JuliaH » Thu 21 Oct 2021 08:22

We have some code which is reading data in string form from a file, which was dumped out of an Oracle DB, using as much precision as the database could support. So, for example:

`var o = OracleNumber.Parse("3.1415926535897932384626433832795028842E0")`

However, there's some truncation going on because `o.Value = 3.14159265358979` (only the first ten bytes of o.BinData are populated). I can't find much information around `OracleNumber.Parse(string, format)` and whether that could be a solution?

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

Re: Truncation in OracleNumber.Parse()

Post by DmitryGm » Fri 22 Oct 2021 15:17

Truncation occurs because the number is in scientific format, with an ordering sign ("E"). Precision will be preserved if you do not use the order sign. For example:

Code: Select all

OracleNumber pi = OracleNumber.Parse("3,1415926535897932384626433832795028842"); 
Console.WriteLine(pi);
Result:

Code: Select all

3,1415926535897932384626433832795028842
Max Precision is presented by the value OracleNumber.MaxPrecision (=38)
See the documentation about OracleNumber:
https://www.devart.com/dotconnect/oracl ... mbers.html

Alternatively, if you want to use the input in exactly this scientific format, you can use the "format" parameter like so:

Code: Select all

OracleNumber pi = OracleNumber.Parse("3.1415926535897932384626433832795028842E0", "9.99999999999999999999999999999999999999999999999999EEEE");
Console.WriteLine(pi);
Note that the "format" parameter will work only if you have installed an Oracle client with the same bitness as your application.

The format is the same as TO_NUMBER function uses. The description of the format can see here:
https://docs.oracle.com/en/database/ora ... 1399F2897C

Post Reply