SciFloat2EStr2 Routines
Converts a Float into a string in Scientific Notation without Padding, except this removes all trailing 0's and the decimal separator if not needed.

Unit
QESBPCSConvert

Overloaded Variants
Function SciFloat2EStr2(const X: Extended; const Decimals: Byte = 4): string;
Function SciFloat2EStr2(const X: Double; const Decimals: Byte = 4): string;
Function SciFloat2EStr2(const X: Single; const Decimals: Byte = 4): string;

Declaration
Function SciFloat2EStr2(const X: Extended; const Decimals: Byte = 4): string;

Description
This is of the form d.dddEnn. ESBBlankWhenZero can be set to True to have Zero returned as an Empty string, where Zero is dependent upon ESBTolerance.

Parameters
Value to Convert to String.
Decimals is the desired number of Decimal places in the Mantissa, defaults to 4

Category
String/Float Conversion Routines

Implementation

function SciFloat2EStr2 (const X: Extended; const Decimals: Byte = 4): string;
var
     P: Integer;
     S1, S2: string;
begin
     if ESBBlankWhenZero and FloatIsZero (X) then
     begin
          Result := '';
          Exit;
     end;

     try
          Result := FloatToStrF (X, ffExponent, Decimals + 1, 0);
          P := ESBPosCh ('E', Result);
          if P > 0 then
          begin
               S1 := LeftStr (Result, P - 1);
               S2 := RightAfterStr (Result, P - 1);
               S1 := StripTChStr (S1, '0');
               if S1 [Length (S1)] = '.' then
                    S1 := LeftStr (S1, Length (S1) - 1);
               Result := S1 + S2;
          end;
     except
          Result := '';
     end;
End;

Declaration
Function SciFloat2EStr2(const X: Double; const Decimals: Byte = 4): string;

Implementation

function SciFloat2EStr2 (const X: Double; const Decimals: Byte = 4): string;
var
     P: Integer;
     S1, S2: string;
begin
     if ESBBlankWhenZero and FloatIsZero (X) then
     begin
          Result := '';
          Exit;
     end;

     try
          Result := FloatToStrF (X, ffExponent, Decimals + 1, 0);
          P := ESBPosCh ('E', Result);
          if P > 0 then
          begin
               S1 := LeftStr (Result, P - 1);
               S2 := RightAfterStr (Result, P - 1);
               S1 := StripTChStr (S1, '0');
               if S1 [Length (S1)] = '.' then
                    S1 := LeftStr (S1, Length (S1) - 1);
               Result := S1 + S2;
          end;
     except
          Result := '';
     end;
End;

Declaration
Function SciFloat2EStr2(const X: Single; const Decimals: Byte = 4): string;

Implementation

function SciFloat2EStr2 (const X: Single; const Decimals: Byte = 4): string;
var
     P: Integer;
     S1, S2: string;
begin
     if ESBBlankWhenZero and FloatIsZero (X) then
     begin
          Result := '';
          Exit;
     end;

     try
          Result := FloatToStrF (X, ffExponent, Decimals + 1, 0);
          P := ESBPosCh ('E', Result);
          if P > 0 then
          begin
               S1 := LeftStr (Result, P - 1);
               S2 := RightAfterStr (Result, P - 1);
               S1 := StripTChStr (S1, '0');
               if S1 [Length (S1)] = '.' then
                    S1 := LeftStr (S1, Length (S1) - 1);
               Result := S1 + S2;
          end;
     except
          Result := '';
     end;
End;


HTML generated by Time2HELP
http://www.time2help.com