可以使用DecimalSeparator来强制Floattostr / Strtofloat函数使用小数点 [英] Is it OK to use DecimalSeparator to force Floattostr/Strtofloat functions to use a decimal point

查看:785
本文介绍了可以使用DecimalSeparator来强制Floattostr / Strtofloat函数使用小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,在使用这些功能的每个过程中,我将DecimalSeparator设置为'。'。

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

开始时全局设置会更容易的程序,但我发现Delphi似乎定期将其设置回当前的区域设置。

It would be much easier to set this globally at the start of the program but I found Delphi seems to periodically set this back to the current locale.

我需要确保一个小数点用于所有转换,无论哪个国家/地区使用该程序,因为这是这种类型的程序的标准,所有文件结构和通信协议,表单/编辑等中的数字显示都需要以这种方式进行格式化。

I need to make sure that a decimal point is used for all conversions no matter which country the program is used in as this is the standard for this type of program and all files structure and communication protocols, numeric displays in forms/edits etc are required to be formatted in this way.

我在另一个线程中被告知,使用decimalseparator不是正确的方式,但我没有给出任何替代方法。我读过的关于这个主题的其他主题似乎没有提供任何形式的指导或者过于复杂。

I've been told in another thread that using decimalseparator is not the correct way to do it but I was not given any alternatives. The other threads concerning this subject that I've read don't seem to offer any formative guidance or are overly complex.

有一种简单的正确方法这个?

Is there a simple 'correct' way to do this ?

推荐答案

我是/假设全局 DecimalSeperator 变量不会被RTL触及。如果没有,那么所有这些例程都可以使用可选的参数 FormatSettings 。 Globaly声明一个 TFormatSettings 变量,并将它用于这些例程的每次出现。

I am/was under the assumption that the global DecimalSeperator variable would not be touched by the RTL. If not, then all these routines have an optional parameter FormatSettings which you could use. Globaly declare a TFormatSettings variable and use it for each occurance of these routines.

它的一个小好处可能是当您指定自己的格式设置时,例程是线程安全的。

A small benefit of it could be that the routines are thread-safe when you specify your own format settings.

这篇关于可以使用DecimalSeparator来强制Floattostr / Strtofloat函数使用小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆