Currency Exato
Função que não faz nenhum tipo de arredondamento, simplesmente trunca o valor recebido em N casas decimal, retornando o valor exato.
Exemplos:
ExatoCurrency(123.45678, 0) => 123
ExatoCurrency(123,45678, 1) => 123,4
ExatoCurrency(123,45678, 2) => 123,45
ExatoCurrency(123,45678, 3) => 123,456
function ExatoCurrency(Value: Currency; Decimal: Integer): Currency;
const
arrDecimal: array[0..3] of Integer = (1, 10, 100, 1000);
begin
if (Abs(Decimal) > 3) then
raise ERangeError.Create(
'TruncExato: O decimal deve está no intervalo de: 0..3');
Result := Trunc(Value * arrDecimal[Decimal]) / arrDecimal[Decimal];
end;