Is it OK to use DecimalSeparator to force Floattostr/Strtofloat functions to use a decimal point

前端 未结 5 1438
天涯浪人
天涯浪人 2021-01-02 08:29

Currently, I\'m setting DecimalSeparator to a \'.\' in each procedure which uses these functions.

It would be much easier to set this globally at the start of the pr

5条回答
  •  天命终不由人
    2021-01-02 09:08

    Yes, the DecimalSeparator global variable might be changed by the RTL during runtime, which caused a lot of headache for me a few years ago before I realised this.

    The thing is that DecimalSeparator is updated by the RTL when the Windows decimal separator is changed, for instance, using the Control Panel. This might seem like a rather small problem. Indeed, how often does the end user change the system's decimal separator?

    The big issue is that the DecimalSeparator variable is updated (according to the system setting) every time you switch user (in Windows). That came as a surprise to me. That is, if your system setting uses a comma (',') as the decimal separator, and you set DecimalSeparator := '.' at application startup, then DecimalSeparator will revert to a comma if you switch user (and you'll notice that when you switch back).

    You can tell the RTL not to update the decimal separator by

    Application.UpdateFormatSettings := false;
    

    At any rate, there are better alternatives to DecimalSeparator, as discussed in other answers and comments.

提交回复
热议问题