Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Numeric Types

Numeric types are used to manipulate numeric values that are too large for the scalar types or numeric values representing currency values. c-treeDB implements the following numeric types:

In This Section

CTBIGINT

CTMONEY

CTCURRENCY

CTNUMBER

Previous Topic

Next Topic

CTBIGINT

CTBIGINT is a 64-bit signed integer type. Today most C compilers are capable of dealing with 64-bit integers. In the Windows operating system, Borland, Microsoft and Watcom use a __int64 type to represent native 64-bit integers, while in other operating systems such as Unix and Linux, 64-bit integers are represented as long long types.

The following set of functions converts of CTBIGINT into other c-treeDB types.

Note: Conversions to CTBIGINT in C++ use a constructor in the format: CTBigint(const [CT type]& value) and are represented below as CTBigint([CT type]).

Method

Operation

AsLong

Convert a CTBIGINT value to a long (32-bit signed integer). If the CTBIGINT value is too large for the conversion, AsLong() returns CTDBRET_OVERFLOW or CTDBRET_UNDERFLOW errors.

AsFloat

Convert a CTBIGINT value to CTFLOAT.

AsString

Convert a CTBIGINT value to string.

CTBigint(CTString)

Convert a string to CTBIGINT value.

Previous Topic

Next Topic

CTMONEY

CTMONEY represents a currency value in a 32-bit signed integer. The last two decimal digits of the value are used as the decimal part of the value. For example, a currency value of 123.45 is represented with CTMONEY as 12345. A currency value of 1 is represented in CTMONEY as 100.

Since all the operations performed on CTMONEY values are integer operations, this type offers exact currency value capabilities that do not need large values or large precision at excellent performance that is very close to 32-bit integer performance.

c-treeDB provides the following set of functions to manipulate CTMONEY values, including functions for performing the basic arithmetic operations on CTMONEY values. These set of basic arithmetic operations are especially important in multiplication and division of CTMONEY values. Take for example the multiplication of two values such as 123.45 and 67.89. These values are represented in a CTMONEY type as 12345 and 6789 respectively. An integer multiplication on the values above, would give the result 83810205, which is 838102.05 in CTMONEY representation. This result is clearly wrong since the expected result would be 8381.02. The same principle applies to division operation. By using the CTMONEY API provided by c-treeDB, the user will be able to operate correctly with CTMONEY values.

Note: Conversions to CTMoney in C++ use a constructor in the format: CTMoney(const [CT type]& value) and are represented below as CTMoney([CT type]). Also, C++ overrides operators (such as +, -, *, and /) so that the result returned is the same type as the items operated upon. For example, the following command would put the result in c as type CTMoney.

c = (CTMoney) a + (CTMoney) b;

In C++, comparison operators can be used for any CT types; the return is a Boolean indicating true or false.

Method

Operation

AsLong

Convert a CTMONEY value to LONG. Only the integer portion of the CTMONEY value is converted to LONG, as the decimal portion of the CTMONEY value is ignored for the conversion.

AsFloat

Convert CTMONEY value to CTFLOAT.

AsString

Convert CTMONEY value to string.

Previous Topic

Next Topic

CTCURRENCY

CTCURRENCY represents a currency value in a 64-bit signed integer. The last four decimal digits of the value are used as the decimal part of the value. Example: a currency value of 123.45 is represented with CTCURRENCY type as 1234500. A currency value of 1 is represented in CTCURRENCY as 10000.

Since all the operations performed on CTCURRENCY values are integer operations, this type offers exact currency value capabilities with large value capabilities and good precision at excellent performance that is very close to 64-bit integer performance.

pResult provides the following set of functions to manipulate CTCURRENCY values, including functions for performing the basic arithmetic operations on CTCURRENCY values. This set of basic arithmetic operations are especially important in multiplication and division of CTCURRENCY values. Take for example the multiplication of two values such as 123.45 and 67.89. These values are represented in a CTCURRENCY type as 1234500 and 678900 respectively. An integer multiplication on the values above would yield 838102050000, which is 83810205.0000 in CTCURRENCY representation. This result is clearly wrong since the expected result would be 8381.02. The same principle applies to division operation. By using the CTCURRENCY API provided by pResult , the user will be able to operate correctly with CTCURRENCY values.

Note: Conversions to CTCurrency in C++ use a constructor in the format: CTCurrency(const [CT type]& value) and are represented below as CTCurrency([CT type]). Also, C++ overrides operators (such as +, -, *, and /) so that the result returned is the same type as the items operated upon. For example, the following command puts the result in c as type CTMoney.

c = (CTCurrency) a + (CTCurrency) b;

In C++, comparison operators can be used for any CT types; the return is a Boolean indicating true or false:

Method

Operation

CTCurrency(CTMoney)

Convert a CTMONEY value to CTCURRENCY value.

AsMoney

Convert a CTCURRENCY value to CTMONEY value.

AsLong

Convert a CTCURRENCY value to a LONG value.

AsBigint

Convert a CTCURRENCY value to CTBIGINT value.

CTCurrency(CTBigint)

Convert a CTBIGINT value to CTCURRENCY value.

AsFloat

Convert a CTCURRENCY value to a CTFLOAT value.

AsString

Convert a CTCURRENCY value to a string.

StringToCurrency

Convert a string to a CTCURRENCY value.

Previous Topic

Next Topic

CTNUMBER

CTNUMBER corresponds to a number with a given precision (maximum number of digits) and scale (the number of digits to the right of the decimal point). Numeric values can have maximum values of 32 digits precision and scale of 0 (this is 99999999999999999999999999999999), which can represent very large exact values.

pResult provides the following set of functions to manipulate this very powerful number representation.

Note: Conversions to CTNumber in C++ use a constructor in the format: CTNumber(const [CT type]& value) and are represented below as CTNumber([CT type]). Also, C++ overrides operators (such as +, -, *, and /) so that the result returned is the same type as the items operated upon. For example, the following command would put the result in c as type CTMoney.

c = (CTNumber) a + (CTNumber) b;

In C++, comparison operators can be used for any CT types; the return is a Boolean indicating true or false.

Method

Operation

AsMoney

Convert CTNUMBER to CTMONEY.

AsLong

Convert CTNUMBER to LONG.

AsBigint

Convert CTNUMBER to CTBIGINT.

AsCurrency

Convert CTNUMBER to CTCURRENCY.

AsFloat

Convert CTNUMBER to CTFLOAT.

AsString

Convert CTNUMBER to string.

Zero

Set the value pointed by pNumber to zero.

IsZero

Return YES if the value is zero.

Round

Round the value pointer by num to the number of decimal digits (digits to the right of the decimal point) indicated by scale.

DecimalDigits

Given the CTNUMBER data, stores the number of digits to the left of the decimal point in digit_before and stores the number of digits to the right of decimal point in digit_after.

TOCIndex