Delphi 如何设置数据集';是否显示与Windows货币格式匹配的格式?
我正在寻找一种方法来读取存储在Windows中的默认货币相关格式信息,并构建一个格式字符串,包括负数的格式,我可以将其用作数据集字段的DisplayFormat 例如,在C#中,货币的格式是“C”(参见) 例如(我在linqpad中运行了它):Delphi 如何设置数据集';是否显示与Windows货币格式匹配的格式?,delphi,delphi-xe8,Delphi,Delphi Xe8,我正在寻找一种方法来读取存储在Windows中的默认货币相关格式信息,并构建一个格式字符串,包括负数的格式,我可以将其用作数据集字段的DisplayFormat 例如,在C#中,货币的格式是“C”(参见) 例如(我在linqpad中运行了它): String.Format(“{0:C}”,-120) 它打印符合我的Windows设置的($120.00) 在Delphi中,我需要一个函数来查看t格式设置属性并构建货币格式字符串,类似这样:$,0.00;($,0.00)(我使用的是英美默认设置)
String.Format(“{0:C}”,-120)
它打印符合我的Windows设置的($120.00)
在Delphi中,我需要一个函数来查看t格式设置
属性并构建货币格式字符串,类似这样:$,0.00;($,0.00)
(我使用的是英美默认设置)
我正在尝试解决DevExpress quantum网格中的一个问题,即具有货币值的列的页脚总和聚合不符合操作系统设置所定义的负数格式。我最终使用了以下代码。前两个函数来自data\data.FMTBcd.pas 在做一些测试时,我注意到一件事,如果我在“控制面板”->“区域和语言”->“其他设置”->“货币”选项卡中更改十进制符号或数字分组符号,t格式设置不会读取这些新值,它总是返回点作为十进制分隔符,逗号作为千位分隔符。相反,它使用数字选项卡中的这些设置
function AddCurrencySymbol(const Value, CurrSymbol: string; const CurrFormat: Byte): string;
begin
case CurrFormat of
0: Result := Format('%s%s', [CurrSymbol, Value]);
1: Result := Format('%s%s', [Value, CurrSymbol]);
2: Result := Format('%s %s', [CurrSymbol, Value]);
3: Result := Format('%s %s', [Value, CurrSymbol]);
end;
end;
{ 0 = '($1)' 4 = '(1$)' 8 = '-1 $' 12 = '$ -1'
1 = '-$1' 5 = '-1$' 9 = '-$ 1' 13 = '1- $'
2 = '$-1' 6 = '1-$' 10 = '1 $-' 14 = '($ 1)'
3 = '$1-' 7 = '1$-' 11 = '$ 1-' 15 = '(1 $)' }
function AddNegCurrencySymbol(const Value, CurrSymbol: string; const CurrFormat: Byte): string;
begin
case CurrFormat of
0: Result := Format('(%s%s)', [CurrSymbol, Value]);
1: Result := Format('-%s%s', [CurrSymbol, Value]);
2: Result := Format('%s-%s', [CurrSymbol, Value]);
3: Result := Format('%s%s-', [CurrSymbol, Value]);
4: Result := Format('(%s%s)', [Value, CurrSymbol]);
5: Result := Format('-%s%s', [Value, CurrSymbol]);
6: Result := Format('%s-%s', [Value, CurrSymbol]);
7: Result := Format('%s%s-', [Value, CurrSymbol]);
8: Result := Format('-%s %s', [Value, CurrSymbol]);
9: Result := Format('-%s %s', [CurrSymbol, Value]);
10: Result := Format('%s %s-', [Value, CurrSymbol]);
11: Result := Format('%s %s-', [CurrSymbol, Value]);
12: Result := Format('%s %s', [CurrSymbol, Value]);
13: Result := Format('%s -%s', [Value, CurrSymbol]);
14: Result := Format('(%s- %s)', [CurrSymbol, Value]);
15: Result := Format('(%s %s)', [Value, CurrSymbol]);
end;
end;
function DefaultCurrencyFormat(formatSettings: TFormatSettings): String;
begin
if formatSettings.CurrencyDecimals > 0 then
Result := '0' + formatSettings.DecimalSeparator + StringOfChar('0', formatSettings.CurrencyDecimals)
else
Result := '0';
Result := formatSettings.ThousandSeparator + Result;
Result := AddCurrencySymbol(Result, formatSettings.CurrencyString, formatSettings.CurrencyFormat)
+ ';' + AddNegCurrencySymbol(Result, formatSettings.CurrencyString, formatSettings.NegCurrFormat)
end;
我最终使用了下面的代码。前两个函数来自data\data.FMTBcd.pas 在做一些测试时,我注意到一件事,如果我在“控制面板”->“区域和语言”->“其他设置”->“货币”选项卡中更改十进制符号或数字分组符号,t格式设置不会读取这些新值,它总是返回点作为十进制分隔符,逗号作为千位分隔符。相反,它使用数字选项卡中的这些设置
function AddCurrencySymbol(const Value, CurrSymbol: string; const CurrFormat: Byte): string;
begin
case CurrFormat of
0: Result := Format('%s%s', [CurrSymbol, Value]);
1: Result := Format('%s%s', [Value, CurrSymbol]);
2: Result := Format('%s %s', [CurrSymbol, Value]);
3: Result := Format('%s %s', [Value, CurrSymbol]);
end;
end;
{ 0 = '($1)' 4 = '(1$)' 8 = '-1 $' 12 = '$ -1'
1 = '-$1' 5 = '-1$' 9 = '-$ 1' 13 = '1- $'
2 = '$-1' 6 = '1-$' 10 = '1 $-' 14 = '($ 1)'
3 = '$1-' 7 = '1$-' 11 = '$ 1-' 15 = '(1 $)' }
function AddNegCurrencySymbol(const Value, CurrSymbol: string; const CurrFormat: Byte): string;
begin
case CurrFormat of
0: Result := Format('(%s%s)', [CurrSymbol, Value]);
1: Result := Format('-%s%s', [CurrSymbol, Value]);
2: Result := Format('%s-%s', [CurrSymbol, Value]);
3: Result := Format('%s%s-', [CurrSymbol, Value]);
4: Result := Format('(%s%s)', [Value, CurrSymbol]);
5: Result := Format('-%s%s', [Value, CurrSymbol]);
6: Result := Format('%s-%s', [Value, CurrSymbol]);
7: Result := Format('%s%s-', [Value, CurrSymbol]);
8: Result := Format('-%s %s', [Value, CurrSymbol]);
9: Result := Format('-%s %s', [CurrSymbol, Value]);
10: Result := Format('%s %s-', [Value, CurrSymbol]);
11: Result := Format('%s %s-', [CurrSymbol, Value]);
12: Result := Format('%s %s', [CurrSymbol, Value]);
13: Result := Format('%s -%s', [Value, CurrSymbol]);
14: Result := Format('(%s- %s)', [CurrSymbol, Value]);
15: Result := Format('(%s %s)', [Value, CurrSymbol]);
end;
end;
function DefaultCurrencyFormat(formatSettings: TFormatSettings): String;
begin
if formatSettings.CurrencyDecimals > 0 then
Result := '0' + formatSettings.DecimalSeparator + StringOfChar('0', formatSettings.CurrencyDecimals)
else
Result := '0';
Result := formatSettings.ThousandSeparator + Result;
Result := AddCurrencySymbol(Result, formatSettings.CurrencyString, formatSettings.CurrencyFormat)
+ ';' + AddNegCurrencySymbol(Result, formatSettings.CurrencyString, formatSettings.NegCurrFormat)
end;
您使用的是哪个版本的Delphi?大多数版本都有一条记录可用于检索操作系统的默认格式值,例如:
Fmt:=t格式设置。Create;//根据需要使用Fmt.CurrencyString、Fmt.CurrencyFormat、Fmt.CurrencyDecimals和Fmt.NegCurrFormat…
XE8。是的,这是正确的,但我希望已经有一个函数可以做到这一点。我现在正在搜索源代码…既然您已经了解了TFormatSetting,那么您在使用它时遇到的实际问题是什么?请显示迄今为止您已尝试的代码。顺便说一句,您是否尝试过使用DevExpress提交错误报告?您看过Delphi的功能了吗?或者的m
(money)说明符?我正处于时间紧迫期,我希望已经有一个函数可以在DelphiAPI或其他地方实现这一点。为了节省时间,我想在这里问这个问题。以前有人遇到这种情况的几率很高。您使用的是哪个版本的Delphi?大多数版本都有一条记录可用于检索操作系统的默认格式值,例如:Fmt:=t格式设置。Create;//根据需要使用Fmt.CurrencyString、Fmt.CurrencyFormat、Fmt.CurrencyDecimals和Fmt.NegCurrFormat…
XE8。是的,这是正确的,但我希望已经有一个函数可以做到这一点。我现在正在搜索源代码…既然您已经了解了TFormatSetting,那么您在使用它时遇到的实际问题是什么?请显示迄今为止您已尝试的代码。顺便说一句,您是否尝试过使用DevExpress提交错误报告?您看过Delphi的功能了吗?或者的m
(money)说明符?我正处于时间紧迫期,我希望已经有一个函数可以在DelphiAPI或其他地方实现这一点。为了节省时间,我想在这里问这个问题。以前有人遇到这种情况的几率很高。