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 in a 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 .NET provides the class CTMoney that exposes the following set of methods to manipulate the CTMONEY values, including functions for performing the basic arithmetic operations on CTMONEY values. This set of basic arithmetic operations is 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 operations. By using the CTMONEY API provided by c-treeDB .NET, the user will be able to operate correctly with CTMONEY 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 would put the result in c as type CTMoney. In C#, comparison operators can be used for any CT types; the return is a Boolean indicating true or false.
c = (CTMoney) a + (CTMoney) b;
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. |