Autor Beitrag
HenryHux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 542
Erhaltene Danke: 33

Windows 7 Premium
Delphi XE, Eclipse
BeitragVerfasst: So 19.12.10 14:07 
Hi,

bei der Typumwandlung von Gleitkommazahlen zu Strings, werden nachkommazahlen ja übelicherweise duch ein , getrennt.
Krieg ich das auch einfach mit nem Punkt hin oder muss ich den String mühsam zerpflücken?

Lg
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 19.12.10 14:14 
StringReplace('1234.234','.',DecimalSeparator,[])

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS

Für diesen Beitrag haben gedankt: HenryHux
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 19.12.10 14:19 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  InvariantSettings: TFormatSettings;
begin
  InvariantSettings.DecimalSeparator := '.';
  ...
  FloatToStr(0.5, InvariantSettings);


Oder, wenn du's global ändern willst: DecimalSeparator := '.';

Oder als erste Unit SetThreadLocale auf English (U.S.) setzen (SetThreadLocale($0409);).

Für diesen Beitrag haben gedankt: HenryHux
HenryHux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 542
Erhaltene Danke: 33

Windows 7 Premium
Delphi XE, Eclipse
BeitragVerfasst: So 19.12.10 14:25 
Danke!
Genau das, was ich suchte.

Lg
dummzeuch
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 593
Erhaltene Danke: 5


Delphi 5 ent, Delphi 6 bis Delphi XE8 pro
BeitragVerfasst: So 19.12.10 20:07 
user profile icondelfiphan hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  InvariantSettings: TFormatSettings;
begin
  InvariantSettings.DecimalSeparator := '.';
  ...
  FloatToStr(0.5, InvariantSettings);


Ahem: Ist das so sinnvoll? Eine nicht initialisierte (Record-)Variable, bei der nur ein einziges Feld gesetzt wird als Parameter uebergeben? Ich haette da zumindest versucht, die Variable mit den Systemeinstellungen vorzubelegen und erst dann das Feld DecimalSeparator zu aendern.

twm
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 20.12.10 00:52 
Nein, natürlich nicht. Ich wollte nur andeuten, wie das zu tun ist. In der Praxis hätte man die Variable vielleicht in globalem Scope oder in einer Klasse und würde die anderen Felder auch definieren.
TheChicken
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 25.10.11 09:41 
Hallo,

ich habe gerade zum wiederholten Male das selbe Problem gehabt und immer irgendwie gelöst. Jedoch meine ich heute endlich mal eine "gute" Lösung gefunden zu haben. Dabei nutze ich ebenfalls die TFormatSettings-Variable, die ich aber vorher mit LOCALE_INVARIANT initialisiere.

Auszug aus der Microsoft Hilfe:
Zitat:
For example, the invariant locale is used when an application compares character strings using the CompareString function and expects a consistent result regardless of the user locale. The settings of the invariant locale are similar to those for English (United States) but should not be used to display formatted data.
Und genau das will man ja haben, wenn man z.B. einen SQL-String mit Float-Werten zusammenbauen will.

Also
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
function FloatToSQLString(Value: Extended): string;
var
  FS: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_INVARIANT, FS);
  Result := FloatToStr(Value, FS);
end;


Wenn auch ein wenig spät... ich hoffe, ich konnte helfen.

TheChicken