Trunc in delphi

106 Views Asked by At

I am trying to separate currency number into two separate integer,

var
  StrNum: string;
  CurDecimalNum: currency;
  Amount : currency;
begin

    Amount := 1868.45;
    StrNum := FormatFloat('00', trunc(frac(Amount) * 100));   // this will return 44

    CurDecimalNum := frac(Amount) * 100;                      //Patch7
    StrNum := FormatFloat('00', trunc(CurDecimalNum));         //Patch7 but here I get 45

end.

I am doing it like this, but there is a problem in the first FormatFloat(), it returns 44 instead of 45.

I already have the solution in the code, I just had to separate the actions into two lines, I am just really curious why is this happening?

1

There are 1 best solutions below

2
MicheleP On

Have you tried to delete this line?

StrNum := FormatFloat('00', trunc(frac(Amount) * 100));