Difference between revisions of "DecimalSeparator"

From Lazarus wiki
Jump to navigationJump to search
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''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...
+
{{DecimalSeparator}}
 +
{{Warning|This variable is deprecated. Please see hints for information on replacement.}}
  
A workaround can be use of a function like:
+
'''DecimalSeparator''' is a [[Global variables|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(). 
  
<syntaxhighlight>
+
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 to use a function like:
 +
 
 +
<syntaxhighlight lang=pascal>
 
function DecFloat2Str( const d: double ): string;
 
function DecFloat2Str( const d: double ): string;
 
var
 
var
Line 17: Line 21:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
[[Category:Global variables]]
+
DecimalSeparator is defined in sysinth.inc as:
 +
  DecimalSeparator : Char absolute DefaultFormatSettings.DecimalSeparator deprecated;
 +
 
 +
== Important hint ==
 +
 
 +
DecimalSeparator is deprecated. In all new projects, it should be replaced by the [[DefaultFormatSettings]] variable.
 +
 
 +
== See also ==
 +
* [[ThousandSeparator]]
 +
* [[ListSeparator]]
 +
* [http://www.freepascal.org/docs-html/rtl/sysutils/decimalseparator.html Documentation on DecimalSeparator]

Latest revision as of 12:00, 6 April 2023

English (en) français (fr)

Warning-icon.png

Warning: This variable is deprecated. Please see hints for information on replacement.

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 to use 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;

Important hint

DecimalSeparator is deprecated. In all new projects, it should be replaced by the DefaultFormatSettings variable.

See also