Skip to content

Commit 683cc93

Browse files
committed
Document DECFLOAT conversions from and to other .NET types
1 parent 2f9500e commit 683cc93

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎docs/decfloat.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
`DECFLOAT(16)` and `DECFLOAT(34)` from Firebird 4 is handled by `FbDecFloat` type. `FbDecFloat` can be used as parameter value for `FbParameter`.
44

5+
### Values are never rounded silently
6+
7+
`DECFLOAT(16)` holds 16 significant digits and `DECFLOAT(34)` holds 34. A value that cannot be represented exactly in the precision or exponent range of the target (for example a 17 digit value passed to a `DECFLOAT(16)` parameter) throws `OverflowException`. Values that only need trailing zeros removed or the exponent adjusted (e.g. `1E384` in `DECFLOAT(16)`) are accepted.
8+
9+
### Other .NET types
10+
11+
Parameters: besides `FbDecFloat`, a `DECFLOAT` parameter accepts `decimal`, `double`, `float`, the integral types and `BigInteger`:
12+
13+
* `decimal` is converted exactly, including its scale (`1.10m` stays `1.10`).
14+
* `double` and `float` are converted to the shortest decimal that converts back to the same binary value (`0.1` is `0.1`, `0.1 + 0.2` is `0.30000000000000004`), which may have up to 17 significant digits.
15+
16+
Reading a `DECFLOAT` column:
17+
18+
* `GetDecimal` is exact; it throws `OverflowException` when the value cannot be represented exactly as `decimal` (too large, too many digits, NaN or infinity).
19+
* `GetDouble` and `GetFloat` return the nearest value (NaN and infinities are mapped).
20+
* `GetInt16`, `GetInt32`, `GetInt64` and `GetByte` round to the nearest integer, ties to even, and throw `OverflowException` when out of range.
21+
22+
`FbDecFloat` has explicit conversions from and to `decimal`, `double` and `float`, with the same rules.
23+
524
### Examples
625

726
Examples can be found in [`FbDecFloat16SupportTests`](../src/FirebirdSql.Data.FirebirdClient.Tests/FbDecFloat16SupportTests.cs) and [`FbDecFloat34SupportTests`](../src/FirebirdSql.Data.FirebirdClient.Tests/FbDecFloat34SupportTests.cs).

0 commit comments

Comments
 (0)