Skip to content

Commit 825447f

Browse files
committed
fix: no locale influence and no scientific notation in JSON reformatter
1 parent a140b19 commit 825447f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

source/generic_types.pas

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44

55
interface
66

7+
uses fpjson, jsonparser, SysUtils;
8+
79
type
810
TThreeStateBoolean = (nbUnset, nbFalse, nbTrue);
911

12+
TJSONFloatNumberUntouched = class(TJSONFloatNumber)
13+
public
14+
function GetAsString: TJSONStringType; override;
15+
end;
16+
1017
TFileExtImageIndex = record
1118
Ext: String;
1219
ImageIndex: Integer;
@@ -50,4 +57,28 @@ function GetFileExtImageIndex(Ext: String): Integer;
5057
end;
5158
end;
5259

60+
{ TJSONFloatNumberUntouched }
61+
62+
function TJSONFloatNumberUntouched.GetAsString: TJSONStringType;
63+
var
64+
Val: TJSONFloat;
65+
fs: TFormatSettings;
66+
begin
67+
fs := DefaultFormatSettings;
68+
fs.DecimalSeparator := '.';
69+
Val := GetAsFloat;
70+
Result := FloatToStrF(Val, ffFixed, 18, 18, fs);
71+
72+
// Trim trailing zeros after the decimal point
73+
while (Length(Result) > 0) and (Result[High(Result)] = '0') do
74+
Delete(Result, High(Result), 1);
75+
// Remove trailing decimal separator if no fractional digits left
76+
if (Length(Result) > 0) and (Result[High(Result)] = fs.DecimalSeparator) then
77+
Delete(Result, High(Result), 1);
78+
end;
79+
80+
initialization
81+
82+
SetJSONInstanceType(jitNumberFloat, TJSONFloatNumberUntouched);
83+
5384
end.

source/texteditor.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface
1010
apphelpers, ActnList, extra_controls,
1111
ExtCtrls, dbconnection, SynEdit, SynEditHighlighter, customize_highlighter,
1212
Laz2_DOM, Laz2_XMLRead, Laz2_XMLWrite,
13-
reformatter, jsonparser, extfiledialog,
13+
reformatter, jsonparser, extfiledialog, generic_types,
1414

1515
SynHighlighterBat,
1616
SynHighlighterCpp, SynHighlighterCss,

0 commit comments

Comments
 (0)