DecimalSeparator

From Lazarus wiki
Revision as of 10:54, 9 October 2015 by Arent (talk | contribs) (Created page with "'''DecimalSeparator''' is a global char variable whose contents is determined by the used locale. It is used for representation of floating point numbers on screen and wit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

DecimalSeparator is a global char variable whose contents is determined by the used locale. It is used for representation of floating point numbers on screen and within functions like StrToFloat() and 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;