You are not logged in.
Pages: 1
procedure TMvcApplication.RatingConvert(const Value: variant; out Result: variant);
var
D: double = 0;
B: boolean;
begin
SetVariantNull(Result);
// Normal
OutputDebugString(PChar(VariantToString(Value)));
VariantToDouble(variant(20.6170212765957), D);
D := Value;
// Abnormal
B := VariantToDouble(Value, D);
end;
Value := 20.6170212765957
I don't know if it's my problem or someone else's problem
Last edited by testgary (2025-06-10 06:13:27)
Offline
Sorry, I don't get what is going on in your code, and what "abnormal" is?
It's not an error, but the data cannot be retrieved if the value is in a format like 20.6170212765957. This is because MongoDB's Double type stores numbers with such long decimal precision.
This is a method I defined using RegisterExpressionHelpers.
(TMvcRunOnRestServer(fMainRunner).Views as TMvcViewsMustache).
RegisterExpressionHelpers(['RatingConvert'], [@RatingConvert]);
Offline
procedure TMvcApplication.DoText(const Value: variant; out Result: variant);
var
D: double = 0;
B: Boolean;
begin
// "D" does not receive a valid result, but integers do
B := VariantToDouble(Value, D);
end;
procedure TMvcApplication.Start(aRestModel: TRest; aInterface: PRttiInfo);
begin
(TMvcRunOnRestServer(fMainRunner).Views as TMvcViewsMustache).
RegisterExpressionHelpers(['DoText'], [@DoText]);
end;
// Frontend template snippet
{{DoText 20.6170212765957}}
Offline
Pages: 1