Conversions Involving Numeric Values

OLE DB Programmer's Reference

Conversions involving numeric values use the following general guidelines:

  • Except for the most significant digit, all digits in floating-point numbers are considered to be less significant. Thus, floating-point numbers can always be converted (possibly with truncation) to integers, numerics, or strings as long as they don't overflow the integer, numeric, or string.

    For example, 1.234567E2 is truncated to 123 when converted to an integer; to 123.4 when converted to a NUMERIC(4, 1); to 120 when converted to a NUMERIC(4, – 1), assuming the provider supports negative scale (many do not); to "123\0" when converted to a 4-byte ANSI string; and to "123.4\0" when converted to a 6-byte ANSI string. It cannot be converted to an ANSI string of 3 or fewer bytes because such a conversion would overflow the string.

  • In conversions from DBTYPE_NUMERIC and DBTYPE_DECIMAL to string values, the conversion is allowed, provided it does not result in truncation to the left of the decimal point. For example, 123.4567 is truncated to "123.4\0" when converted to a 6-byte ANSI string but returns a truncation error when attempting to convert to a 2-byte ANSI string.
  • In conversions from DBTYPE_NUMERIC to other numeric types, the conversion is allowed, provided the difference between the source value and the target value is less than the difference between two successive values in the target data type. For example, 123.4567 can be converted with a scale of 2 to the numeric value 123.45 because the difference between 123.4567 and 123.45 is less than .01 (10-2).
  • In strings that represent numbers, digits to the right of the decimal point are considered less significant and can be truncated; digits to the left of the decimal point are considered significant and cannot be truncated. For example, "123.45\0" is truncated to 123 when converted to an integer and to 123.4 when converted to a NUMERIC(4, 1). However, the string "1234.5\0" cannot be converted to a 1-byte integer.
  • It is provider-specific whether negative numbers are truncated up or down.
    Thus, –1.99 might be truncated to –1 or to –2 when converted to an integer.

1998-2001 Microsoft Corporation. All rights reserved.



Microsoft Ole Db 2.0 Programmer's Reference and Data Access SDK
Microsoft OLE DB 2.0 Programmers Reference and Data Access SDK (Microsoft Professional Editions)
ISBN: 0735605904
EAN: 2147483647
Year: 1998
Pages: 1083

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net