DelphiBasics
Currency
Type
A decimal type with 4 decimal points used for financial values System unit
type Currency;
Description
The Currency type is designed for use in financial applications. It supports 4 decimal places with at least 53 bits precision*.
 
Decimal places beyond the supported 4 are rounded up or down, as appropriate. See the sample code for an example.
Notes
* Depends on the processor floating point precision.

Very large Currency values will lose precision with some of the StrUtils functions.
Related commands
CurrToStrConvert a currency value to a string
CurrToStrFConvert a currency value to a string with formatting
DoubleA floating point type supporting about 15 digits of precision
ExtendedThe floating point type with the highest capacity and precision
PCurrencyPointer to a Currency value
SingleThe smallest capacity and precision floating point type
StrToCurrConvert a number string into a currency value
 Download this web site as a Windows program.




 
Example code : Rounding up and down currency amounts
var
  account1, account2, account3 : Currency;
begin
  account1 := 123.456749;  // Too many decimals - will be rounded down
  account2 := 123.456750;  // Too many decimals - will be rounded up
  account3 := account1 + account2;

  ShowMessage('Account1 = '+CurrToStr(account1));
  ShowMessage('Account2 = '+CurrToStr(account2));
  ShowMessage('Account3 = '+CurrToStr(account3));
end;
Show full unit code
  Account1 = 123.4567
  Account2 = 123.4568
  Account3 = 246.9135
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page