Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Format + Float    [ Add a report in this area ]  
Report #:  92265   Status: Open
TextToFloat ignores ThousandSeparator
Project:  Delphi Build #:  15.0.3890.34076
Version:    15.1 Submitted By:   Alexey Beloborodov
Report Type:  Suggestion / Enhancement Request Date Reported:  3/13/2011 8:32:11 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   282226
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
SysUtils.TextToFloat ignores ThousandSeparator, so code like this will fail:

GetLocaleFormatSettings(0, fs);
fs.DecimalSeparator:=".";
fs.ThousandSeparator:=",";

d:=12345.67;
s:=FloatToStrF(d, ffNumber, 6, 6, fs);
// OK, s= '12,345.700000'

d:=StrToFloat(s, fs);
// Exception
// EConvertError: '12,345.700000' is not a valid floating point value.

So there is no way to convert correctly formatted string back to double with the same TFormatSettings settings.

This is documented for StrToFloat (which uses TextToFloat internally)

http://docwiki.embarcadero.com/VCL/en/SysUtils.StrToFloat
("Thousand separators and currency symbols are not allowed in the string")

but this is not mentioned in TextToFloat documentation
http://docwiki.embarcadero.com/VCL/en/SysUtils.TextToFloat

Please, add handling of ThousandSeparator in TextToFloat.
Steps to Reproduce:
Create new VCL application, drop a button on the form.

procedure TForm1.Button1Click(Sender: TObject);
var
d: double;
s: string;
fs: TFormatSettings;
begin
GetLocaleFormatSettings(0, fs);
fs.DecimalSeparator:='.';
fs.ThousandSeparator:=',';

d:=12345.67;
s:=FloatToStrF(d, ffNumber, 6, 6, fs);
ShowMessage(s); // OK, s= '12,345.700000'

try
  d:=StrToFloat(s, fs);                // the same TFormatSettings settings
  ShowMessage(FloatToStr(d));
except
  on E: EConvertError do ShowMessage('EConvertError: '+E.Message);
  // EConvertError: 12,345.700000' is not a valid floating point value
end;
end;
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 3/13/2011 5:33:46 PM -
Could you please attach sample project to verify your issue?

Alexey Beloborodov at 3/14/2011 1:48:14 AM -
Happy to see you alive!

I've updated steps.

Tomohiro Takahashi at 3/14/2011 5:18:07 AM -
> Happy to see you alive!
> I've updated steps.
Thanks!!

So, is your issue same as(related to) QC#65102 ?

Alexey Beloborodov at 3/14/2011 8:46:24 AM -
Yes, it's the same problem.

Server Response from: ETNACODE01