diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 97cc3e783d..60bda600c0 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -8588,7 +8588,13 @@ begin begin // integer to integer -> value Result:=ConvertElement(Param,AContext); - if to_bt=btCurrency then + if ParamResolved.BaseType=btCurrency then + begin + if to_bt<>btCurrency then + // currency to integer -> Math.floor(value/10000) + Result:=CreateMathFloor(Param,CreateDivideNumber(Param,Result,10000)); + end + else if to_bt=btCurrency then // integer to currency -> value*10000 Result:=CreateMulNumber(Param,Result,10000); if (to_bt<>btIntDouble) and not (Result is TJSLiteral) then @@ -15240,12 +15246,21 @@ begin end else if AssignContext.LeftResolved.BaseType=btCurrency then begin - if AssignContext.RightResolved.BaseType<>btCurrency then + if AssignContext.RightResolved.BaseType=btCurrency then + // currency := currency + else if AssignContext.RightResolved.BaseType in btAllJSFloats then begin // currency := double -> currency := Math.floor(double*10000) AssignContext.RightSide:=CreateMulNumber(El,AssignContext.RightSide,10000); AssignContext.RightSide:=CreateMathFloor(El,AssignContext.RightSide); - end; + end + else if AssignContext.RightResolved.BaseType in btAllJSInteger then + begin + // currency := integer -> currency := double*10000 + AssignContext.RightSide:=CreateMulNumber(El,AssignContext.RightSide,10000); + end + else + RaiseNotSupported(El,AContext,20181016094542,GetResolverResultDbg(AssignContext.RightResolved)); end else if AssignContext.RightResolved.BaseType=btCurrency then begin diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 9a4cac8fc8..199f796b03 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -5459,8 +5459,13 @@ begin ' c:=a;', ' d:=c;', ' c:=d;', + ' c:=currency(c);', ' c:=currency(d);', ' d:=double(c);', + ' c:=i;', + ' c:=currency(i);', + //' i:=c;', not allowed + ' i:=nativeint(c);', ' c:=c+a;', ' c:=-c-a;', ' c:=d+c;', @@ -5522,8 +5527,12 @@ begin '$mod.c = $mod.a;', '$mod.d = $mod.c / 10000;', '$mod.c = Math.floor($mod.d * 10000);', + '$mod.c = $mod.c;', '$mod.c = $mod.d * 10000;', '$mod.d = $mod.c / 10000;', + '$mod.c = $mod.i * 10000;', + '$mod.c = $mod.i * 10000;', + '$mod.i = Math.floor($mod.c / 10000);', '$mod.c = $mod.c + $mod.a;', '$mod.c = -$mod.c - $mod.a;', '$mod.c = ($mod.d * 10000) + $mod.c;',