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

Invalid NUMBER representation in flcJSON.pas #3

Open
vlad-mal opened this issue Apr 15, 2016 · 0 comments
Open

Invalid NUMBER representation in flcJSON.pas #3

vlad-mal opened this issue Apr 15, 2016 · 0 comments

Comments

@vlad-mal
Copy link

vlad-mal commented Apr 15, 2016

Hello!
In advance, sorry for my poor english.

In accordance with the specifications of JSON (see http://www.json.org/), about Number type.
Number is:
It is a double precision floating-point format in JavaScript (Octal and hexadecimal formats are not used).
...
In accordance with the definition, the DOT (".") must be used as the decimal separator. In your implementation of JSON (in flcJson.pas), you use FloatToStr and StrToFloat function, which as a decimal value used Delphi DecimalSeparator global constant, which contradicts the requirements of the JSON specification. For example, in Russia as DecjmalSeparator used COMMA, therefore your flcJson module in Russia can not be used.

In accordance with the foregoing, I propose:

  1. Into flcJson.pas module add two functions:
function FloatToStrDot (aValue: extended): string;
var
 fFormatSettings : TFormatSettings;
begin
  GetLocaleFormatSettings (GetThreadLocale, fFormatSettings);
  fFormatSettings.DecimalSeparator := '.';
  Result := FloatToStr (aValue, fFormatSettings);
end;

function StrToFloatDot (aValue : string) : Extended;
var
  fDummy : Integer;
begin
  Val(aValue, Result, fDummy);
  if fDummy <> 0 then
    raise Exception.CreateFmt('Invalid float value: "%s"', [aValue]);
end;
  1. Using the above-mentioned functions in all flcJson.pas module instead
    FloatToStr and StrToFloat.
Regards, 
Malinovsky Vladimir.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant