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

前端 未结 5 1435
天涯浪人
天涯浪人 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条回答
  •  旧时难觅i
    2021-01-02 08:58

    It's OK if you have no alternative. Prefer the versions of those functions that accept a TFormatSettings parameter, if your Delphi version is recent enough, so that you don't interfere with any other code that relies on that global variable for locale-aware behavior.

    FloatToStr and StrToFloat are locale-sensitive functions. If you need to convert your floating-point value to a string to persist it somewhere that a program will read later (such as to a file, the registry, or a network socket), then you should use the locale-independent functions Str and Val for your conversions instead. They always use . for the decimal separator, regardless of the DecimalSeparator variable or other environmental settings.

提交回复
热议问题