Money calculations

Hello, Last time I checked the Currency type is not available for the web dialect of pascal. What do you recommend for doing money calculations?

Regards,
Mike

currency type is available

Test code I used here:

var
  a,b,c: currency;
begin
  a := 1.2;
  b := 3.4;
  c := a + b;
  console.log(c);
end;

and this works as expected.

Thanks Bruno. Do you know if this uses the underlying JS Single type? or does it work like the Delphi currency type?

Maps on double

Thank you

You can use this for numeric calculations but note that floating point operations will mess up the decimals. So convert it again or each time.

Kind Regards

function Num_18_0(const nNum : Double): Double;
function Num_18_2(const nNum : Double): Double;
function Num_18_4(const nNum : Double): Double;
function RoundNumber(ANumber: Double; ADecimal: Integer): Double;

function RoundNumber(ANumber: Double; ADecimal: Integer): Double;
var
LCorrection: Double;
begin
if (ANumber=0) then
begin
Result := 0;
Exit;
end;

LCorrection := (5 / Power(10, (ADecimal+3)));

if (ANumber<0) then
LCorrection := -LCorrection;

Result := RoundTo((ANumber + LCorrection), -1 * ADecimal);
end;

function Num_18_0(const nNum : Double): Double;
begin
Result := RoundNumber(nNum, 0);
end;

function Num_18_2(const nNum : Double): Double;
begin
Result := RoundNumber(nNum, 2);
end;

function Num_18_4(const nNum : Double): Double;
begin
Result := RoundNumber(nNum, 4);
end;