Here is some old Delphi code that you could use to get more out of floating points strings before using TryParse()
.
It will sanitize numbers like .25E4 or 10.E2 or -.24, all illegal in Double.TryParse
.
The code will also replace all non-floating point characters by a decimal separator (the 'easiest' way I found to get rid of locale problems).
function ExpandFloatStr(Value: string): string;
var
i : Integer;
sep : Char;
begin
sep := GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.');
Result := Value;
for i := 1 to Length(Result) do
if not ((Result[i] in ['0'..'9', '-', '+', 'e', 'E']) or IsAlpha(Result[i])) then
Result := StringReplace(Result, Result[i], sep, [rfReplaceAll]);
if (Copy(Result, 1, 1) = sep) then
Result := '0' + Result;
if (Copy(Result, 1, 2) = '-' + sep) or (Copy(Result, 1, 2) = '+' + sep) then
Result := copy(Result, 1, 1) + '0' + copy(Result, 2, Length(Result));
if (Pos('E', Result) > 1) and (Copy(Result, Pos('E', Result) - 1, 1) = sep) then
Result := Copy(Result, 1, Pos('E', Result) - 1) + '0' +
Copy(Result, Pos('E', Result), Length(Result));
end;