DecimalSeparator: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | > **Warning:** This variable is deprecated. Please see hints for information on replacement. | |
| 2 | 2 | ||
| 3 | 3 | **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(). | |
| 4 | 4 | ||
| 5 | 5 | 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... | |
| 6 | 6 | ||
| 7 | 7 | A workaround can be to use a function like: | |
| 8 | 8 | ||
| 9 | 9 | ``` pascal | |
| 10 | 10 | function DecFloat2Str( const d: double ): string; | |
| 11 | 11 | var | |
| 12 | 12 | myseparator: char; | |
| 13 | 13 | begin | |
| 14 | 14 | myseparator := DecimalSeparator; | |
| 15 | 15 | DecimalSeparator := '.'; | |
| 16 | 16 | Result := FloatToStr( d ); | |
| 17 | 17 | DecimalSeparator := myseparator; | |
| 18 | 18 | end; | |
| 19 | 19 | ``` | |
| 20 | 20 | ||
| 21 | 21 | DecimalSeparator is defined in sysinth.inc as: | |
| 22 | 22 | ||
| 23 | - | ||
| 23 | + | ```text | |
| 24 | + | DecimalSeparator : Char absolute DefaultFormatSettings.DecimalSeparator deprecated; | |
| 25 | + | ``` | |
| 24 | 26 | ||
| 25 | 27 | ## Important hint | |
| 26 | 28 | ||
| 27 | 29 | DecimalSeparator is deprecated. In all new projects, it should be replaced by the [[DefaultFormatSettings]] variable. | |
| 28 | 30 | ||
| 29 | 31 | ## See also | |
| 30 | 32 | ||
| 31 | 33 | - [[ThousandSeparator]] | |
| 32 | 34 | - [[ListSeparator]] | |
| 33 | 35 | - [Documentation on DecimalSeparator](http://www.freepascal.org/docs-html/rtl/sysutils/decimalseparator.html) | |
| 34 | 36 | ||
| 35 | 37 | --- | |
| 36 | 38 | *From the Free Pascal wiki, page "DecimalSeparator", as it stood on 2023-04-06 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
