unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, LazUTF8;
type
{ TForm1 }
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
function PointlessUserErrorCorrection (FormatString: string): string;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
function TForm1.PointlessUserErrorCorrection (FormatString: string): string;
const
c_ThousandSeparator = ',';
c_DigitPlaceHolder = '#';
function GetThousandSeparatorPosition : word;
begin
Result:= UTF8pos(c_ThousandSeparator, FormatString);
end;
begin
if GetThousandSeparatorPosition > 0 then
begin
while GetThousandSeparatorPosition > 0 do
UTF8Delete(FormatString, 1, GetThousandSeparatorPosition);
while UTF8Copy(FormatString, 1, 1) = c_DigitPlaceHolder do
UTF8Delete(FormatString, 1, 1);
UTF8Insert(c_ThousandSeparator, FormatString, 1);
end;
Result:= FormatString;
end;
procedure TForm1.FormCreate(Sender: TObject);
function WriteFormatFloat
(const FormatString: string;
const Number: real): string;
var
fs: TFormatSettings;
begin
fs.DecimalSeparator := '.';
fs.ThousandSeparator := ',';
Result:=
FormatFloat(FormatString, Number, fs)+
' ('+FormatString+') '+
'PointlessUserErrorCorrection OFF'+LineEnding;
Result:=
Result+
FormatFloat(PointlessUserErrorCorrection(FormatString), Number, fs)+
' ('+PointlessUserErrorCorrection(FormatString)+') '+
'PointlessUserErrorCorrection ON'+ LineEnding;
Result:=
Result+ LineEnding;
end;
var
Temp: string;
begin
Memo1.Lines.Clear;
Memo1.ScrollBars:=ssBoth;
Temp := '';
Temp := Temp + WriteFormatFloat('###,##0.00', 1000);
Temp := Temp + WriteFormatFloat('###,##0.00', 10000);
Temp := Temp + WriteFormatFloat('###,##0.00', 10000000 / 1024);
Temp := Temp + WriteFormatFloat('###,##0.00', 10000000000 / 1024);
Temp := Temp + WriteFormatFloat('###,##0.00', 10000000000 / (1024*1024));
Temp := Temp + WriteFormatFloat('###,##0.00', 100000000000 / (1024*1024));
Temp := Temp + WriteFormatFloat('#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,0.00', 1000);
Temp := Temp + WriteFormatFloat('###,,,###,,,###,,,###,,,###,,,0.00', 1000);
Memo1.Lines.Add(Temp);
end;
end.