Beispiel #1
0
        private static decimal ReadDecimalSafely(DbDataReader reader, int index, int newPrecision, int newScale)
        {
            var nativeReader = (OracleDataReader)reader;
            var result       = OracleDecimal.ConvertToPrecScale(nativeReader.GetOracleDecimal(index), newPrecision, newScale);

            return(result.Value);
        }
        /// <summary>
        /// .NET Decimal has a max precision of 28, so we need to set it here to prevent overflow errors (#708477)
        /// </summary>
        internal static decimal FixDecimalPrecision(OracleDecimal value)
        {
            int nrDigitsIntegerPart = OracleDecimal.Floor(value).ToString().Length;

            try {
                // Try to convert to a decimal with 29 digits
                return(OracleDecimal.ConvertToPrecScale(value, 29, 29 - nrDigitsIntegerPart).Value);
            } catch (OverflowException) {
                // Value didn't fit a decimal with 29 digits, try with 28 digits
                return(OracleDecimal.ConvertToPrecScale(value, 28, 28 - nrDigitsIntegerPart).Value);
            }
        }