Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Variants    [ Add a report in this area ]  
Report #:  99599   Status: Open
Variant does not fully support Extended type - FormatFloat or FloatToStrF Variant problem
Project:  Delphi Build #:  2010, XE
Version:    15.1 Submitted By:   Hakan APAYDIN
Report Type:  Suggestion / Enhancement Request Date Reported:  10/4/2011 5:50:05 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   287994
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Hello, please check this code. Last digit problem.

----------------
procedure TForm1.Button1Click(Sender: TObject);
var
aValue: Variant;
str: string;
begin
aValue := 11111111111111.1234;

str := FloatToStrF(aValue, ffFixed,18,4);
//result(NG): 11111111111111.1230
ShowMessage(str);

str := FormatFloat('.####', aValue);
//result(NG): 11111111111111.123
ShowMessage(str);
end;
----------------

----------------
procedure TForm1.Button2Click(Sender: TObject);
var
aValue: Extended;
str: string;
begin
aValue := 11111111111111.1234;

str := FloatToStrF(aValue, ffFixed,18,4);
//result(OK): 11111111111111.1234
ShowMessage(str);

str := FormatFloat('.####', aValue);
//result(OK): 11111111111111.1234
ShowMessage(str);
end;
----------------
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 10/4/2011 6:21:09 AM -
I modified your code to clarify your case.

Hakan APAYDIN at 10/4/2011 6:34:07 AM -
Thank you for information. "variant" instead of "extended" is used are not a problem.

But third-party component used in the "variant" is a problem for use. component of the "variant" is not possible to make extended.

Tomohiro Takahashi at 10/4/2011 5:49:50 PM -
Thanks for your comment.
I changed [Type] and [Description] field as Sysop.

Tomohiro Takahashi at 10/4/2011 6:41:47 AM -
This case is related to _VarFromXXX and _VarToXXX functions in Variants unit.
-----------------
procedure _VarFromCurr;
begin
...
end;
...
procedure _VarFromReal;
begin
...
end;
...
function _VarToReal(const V: TVarData): Extended;
begin
  Result := _VarToDouble(V);
end;
...
...
function _VarToDouble(const V: TVarData): Double;
begin
  case V.VType of
    ...
    varCurrency: Result := V.VCurrency;
  ...
  ...
-----------------

Tomohiro Takahashi at 10/4/2011 6:58:54 AM -
Please see also documentation about Variant type.
[Variant Types (Delphi) - Variant Type Conversions]
http://docwiki.embarcadero.com/RADStudio/XE2/en/Variant_Types#Variant_Type_Conversions

and,
  Extended type is 10-byte(80bit)
  Real(Double) type is 8-byte(64bit)

Tomohiro Takahashi at 10/4/2011 7:03:02 AM -
Hakan-san
Do you want to put Extended variable into Variant type without loss?

Note:
  With 64bit mode in Delphi XE2, Extended type is 8-byte(64bit).

Server Response from: ETNACODE01