mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-12 20:41:16 +02:00
TAChart: Add size-dependent string formatting function (FloatToStrEx)
git-svn-id: trunk@63610 -
This commit is contained in:
parent
ac1050003a
commit
1645c29059
@ -341,6 +341,8 @@ procedure Exchange(var A, B: Double); overload; inline;
|
||||
procedure Exchange(var A, B: TDoublePoint); overload; inline;
|
||||
procedure Exchange(var A, B: String); overload; inline;
|
||||
|
||||
function FloatToStrEx(x: Double; APrecision: Integer; AFormat: String = '%.3g';
|
||||
AExpFormat: String = '%.3e'; NaNStr: String = 'n/a'): String;
|
||||
function FormatIfNotEmpty(AFormat, AStr: String): String; inline;
|
||||
|
||||
function IfThen(ACond: Boolean; ATrue, AFalse: TObject): TObject; overload;
|
||||
@ -451,6 +453,26 @@ begin
|
||||
B := t;
|
||||
end;
|
||||
|
||||
{ When abs(x) is between 10^-Precision and 10^+Precision the value is formatted
|
||||
with "normal" format AFormat, otherwise with exponential format AExpFormat, }
|
||||
function FloatToStrEx(x: Double; APrecision: Integer; AFormat: String = '%.3g';
|
||||
AExpFormat: String = '%.3e'; NaNStr: String = 'n/a'): String;
|
||||
var
|
||||
LowerLimit, UpperLimit: Double;
|
||||
begin
|
||||
if IsNaN(x) then
|
||||
Result := NaNStr
|
||||
else
|
||||
begin
|
||||
UpperLimit := IntPower(10.0, abs(APrecision));
|
||||
LowerLimit := 1.0 / UpperLimit;
|
||||
if InRange(abs(x), LowerLimit, UpperLimit) or (AExpFormat = '') then
|
||||
Result := Format(AFormat, [x])
|
||||
else
|
||||
Result := Format(AExpFormat, [x]);
|
||||
end;
|
||||
end;
|
||||
|
||||
function FormatIfNotEmpty(AFormat, AStr: String): String;
|
||||
begin
|
||||
if AStr = '' then
|
||||
|
Loading…
Reference in New Issue
Block a user