在德尔福开发的服务中进行浮点转换



我在Delphi中开发了一个使用DataSnap和Tethering的服务,它将信息发送到连接的客户端。现在,当您使用函数"FormatFloat ('$, 0.###',字段("它给了我另一种格式,即它不会以我在 Windows 中配置的格式发送我,"."对于千位分隔符和","作为小数,但恰恰相反。我希望 15674.45 是 15.647,45 美元而不是 15,647.45 美元。但我不想强制使用格式。

procedure TServerContainerSGV40.tapServicioResourceReceived(const Sender: TObject; const AResource: TRemoteResource);
var
identifier, hint, cadena: string;
ID_PRODUCTO: Integer;
codigo, descripcion: string;
ppp, stock, precio_venta: Real;
begin
if AResource.ResType = TRemoteResourceType.Data then
begin
identifier := Copy(AResource.Hint, 1, Pos('}', AResource.Hint));
hint := AResource.Hint.Replace(identifier, '');
cadena := AResource.Value.AsString;
if cadena = 'Get IP' then EnviarCadena(AResource.Hint, 'Envío IP', GetLocalIP);
if hint = 'Datos Producto' then
begin
if cadena.Length > 0 then
begin
with usGetDatosProducto do
begin
ParamByName('CODIGO').AsString := cadena;
Execute;
ID_PRODUCTO := ParamByName('ID_PRODUCTO').AsInteger;
codigo := ParamByName('CODIGO').AsString;
descripcion := ParamByName('DESCRIPCION').AsString;
ppp := ParamByName('PPP').AsFloat;
stock := ParamByName('STOCK').AsFloat;
precio_venta := ParamByName('PRECIO_VENTA').AsFloat;
end;
if ID_PRODUCTO > 0 then
begin
cadena := Format('%s;%s;;PRECIO:'#9'%s;P.P.P.:'#9'%s;STOCK:'#9'%s', [
codigo, descripcion, FormatFloat('$ ,0', precio_venta),
FormatFloat('$ ,0.##', ppp), FormatFloat(',0.###', stock)
]);
EnviarCadena(identifier, 'Envío Datos Producto', cadena);
end
else
EnviarCadena(identifier, 'Mostrar Mensaje', 'Código de Producto No Existe');
end;
end;
end;
end;

默认情况下,FormatFloat()使用全局SysUtils.ThousandsSeparatorSysUtils.DecimalSeparator变量,这些变量程序启动时从操作系统设置初始化:

FormatFloat('$#,##0.00', field);

如果要强制使用特定格式而不考虑操作系统设置,请使用将TFormatSettings作为输入的重载版本的FormatFloat()

var
fmt: TFormatSettings;
fmt := TFormatSettings.Create;
fmt.ThousandsSeparator := '.';
fmt.DecimalSeparator := ',';
FormatFloat('$#,##0.00', field, fmt);

在 D2009 的 Delphi 版本中(至少(,您可以为给定操作指定格式设置,并通过 Windows 默认设置或修改所需的格式字段来初始化这些设置。

function FormatFloat(const Format: string; Value: Extended): string; overload;
function FormatFloat(const Format: string; Value: Extended; 
const FormatSettings: TFormatSettings): string; overload;

我想知道 - 是否不可能仅用Format函数形成所有字符串?

最新更新