Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double to json bug #15

Open
GoogleCodeExporter opened this issue Jun 22, 2015 · 5 comments
Open

double to json bug #15

GoogleCodeExporter opened this issue Jun 22, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Delphi7 
Windows xp

procedure TForm1.Button1Click(Sender: TObject);
var
  jo: ISuperObject;
begin
  jo := so('{a:1}');
  jo.D['a']:=1.0;
  ShowMessage(jo.AsJSon(False,false));
end;

output:
{"a":1.}

  '1.' is not a valid json number,it should be '1.0'

Original issue reported on code.google.com by [email protected] on 21 Feb 2011 at 3:49

@GoogleCodeExporter
Copy link
Author

Currency has the same Problem. Double uses some externel gcvt function, but 
currency uses the CurrToStr. So its easy to fix: 
Move SetLength(Result, len+1); 
After if c <> 0 then 

Correct Code:

  Result := IntToStr(Abs(PInt64(@c)^));
  len := Length(Result);
  if c <> 0 then
  begin
    SetLength(Result, len+1);



Original comment by [email protected] on 23 Sep 2011 at 8:57

@GoogleCodeExporter
Copy link
Author

There are more errors 100 will also produce an 100.

Don't know whar stuff CurrToStr is doing. For now an Exit after Result := 
IntToStr(Abs(PInt64(@c)^)); works fine

Original comment by [email protected] on 23 Sep 2011 at 9:45

@GoogleCodeExporter
Copy link
Author

well not quite good, didn't look right inttostr cuts of everything after the 
comma.

so just do

function CurrToStr(c: Currency): SOString;
var
  formatSettings: TFormatSettings;
begin
  formatSettings.DecimalSeparator := '.';
  Result:=FloatToStr(c,formatSettings);
end;

Original comment by [email protected] on 23 Sep 2011 at 12:45

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

1. Put the below function just under the gcvt definition.

function FloatToStr(c: Double): SOString;
var
  fbuffer: array[0..31] of AnsiChar;
begin
  Result := SOString(gcvt(c, 15, fbuffer));
  if (Result[length(Result)] = '.') then result := result + '0';
end;

2. Replace -> Result := Append(PSOChar(SOString(gcvt(FO.c_double, 15, 
fbuffer))));
   with    -> Result := Append(PSOChar(FloatToStr(FO.c_double)));

Original comment by [email protected] on 12 Jun 2013 at 10:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant