- This topic has 1 reply, 2 voices, and was last updated 2 years, 6 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Home › Forums › kbmMW › Function TkbmMWJSONStreamer.ExpectNumber doesn’t work with exp floating values
Tagged: JSON
Hi
Function shows error during the parsing float values with exp values (like 1.2E+7 or 1.2E-8)
I think this function needs to be changed
function TkbmMWJSONStreamer.ExpectNumber(var AIsInteger:boolean):double;
var
sb:TkbmMWStringBuilder;
bDot:boolean;
bExp:boolean;
begin
bDot:=false;
bExp:=false;
sb:=TkbmMWStringBuilder.Create;
try
while (FPos<=FLength-KBMMW_STRINGCHARLENOFS) do
begin
case FSource[FPos] of
‘0’,
‘1’,
‘2’,
‘3’,
‘4’,
‘5’,
‘6’,
‘7’,
‘8’,
‘9’:
begin
sb.Append(FSource[FPos]);
inc(FPos);
end;
‘-‘:
begin
// vad if (sb.Length>0) then
if (sb.Length>0) and (not bExp) then
break;
sb.Append(FSource[FPos]);
inc(FPos);
end;
‘+’:
begin
// vad if (sb.Length>0) then
if (sb.Length>0) and (not bExp) then
break;
sb.Append(FSource[FPos]);
inc(FPos);
end;
‘.’:
begin
if bDot then
break;
sb.Append(FSource[FPos]);
inc(FPos);
bDot:=true;
end;
‘e’,
‘E’:
begin
if bExp then
break;
sb.Append(FSource[FPos]);
inc(FPos);
bExp:=true;
end
else
break;
end;
end;
AIsInteger:=not (bDot or bExp);
Result:=StrToFloat(sb.ToString,kbmMWONDefaultFormat.FormatSettings);
finally
sb.Free;
end;
end;
Hi,
Thank you for your bugreport.
Parsing scientific numbers will be improved in next release for both JSON and YAML.
/Kim