Product Documentation

c-treeDB API for C# - Developers Guide

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. For example, a currency value of 123.45 is represented in a 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.

c-treeDB .NET provides the class CTCurrency that exposes the following set of methods to manipulate CTCURRENCY values, including functions for performing the basic arithmetic operations on CTCURRENCY values. This set of basic arithmetic operations is 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 c-treeDB .NET, the user will be able to operate correctly with CTCURRENCY values.

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 CTCurrency. In C#, comparison operators can be used for any CT types; the return is a Boolean indicating true or false:

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

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.

TOCIndex