DecimalSeparator/fr

From Free Pascal wiki
Revision as of 08:40, 9 November 2016 by E-ric (talk | contribs) (Created page with " {{DecimalSeparator}} '''DecimalSeparator''' est une variable char globale dont le contenu est déterminé par la locale utilisée. Elle es...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

English (en) français (fr)

DecimalSeparator est une variable char globale dont le contenu est déterminé par la locale utilisée. Elle est utilisée pour la représentation des nombres flottants sous forme de chaîne de caractères dans les fonctions StrToFloat() et FloatToStr().


As long as every instance of a program uses the same decimal separator everything will behave as expected. However, if one instance of a program has its locale set to Dutch (nl_NL), writes a file containing some floating point numbers which is read by another instance of the same program with a locale set to US-English (en_US) you run into trouble because a formatted number like 123,456 will generate a conversion exception...

A workaround can be use of a function like:

function DecFloat2Str( const d: double ): string;
var
   myseparator: char;
begin
  myseparator := DecimalSeparator;
  DecimalSeparator := '.';
  Result := FloatToStr( d );
  DecimalSeparator := myseparator;
end;

DecimalSeparator is defined in sysinth.inc as:

 DecimalSeparator : Char absolute DefaultFormatSettings.DecimalSeparator deprecated;

See also