听说货币类型用float,double,在计算时会有精度损失。那么下面的这个ftFloat类型,想在数据库中做为货币类型使用,在计算时会有精度损失吗?我也想直接用ftCurrency,可是因为我用的控件不支持ftCurrency啊。但是他支持ftFloat,并且是按下面的代码定义的。const
DefaultFieldClasses : Array [TFieldType] of TFieldClass =
( { ftUnknown} Tfield,
{ ftString} TStringField,
{ ftSmallint} TSmallIntField,
{ ftInteger} TLongintField,
{ ftWord} TWordField,
{ ftBoolean} TBooleanField,
{ ftFloat} TFloatField,
... { TFloatField } TFloatField = class(TNumericField)
private
FCurrency: Boolean;
FMaxValue : Double;
FMinValue : Double;
FPrecision : Longint;
procedure SetCurrency(const AValue: Boolean);
protected
function GetAsFloat: Double; override;
function GetAsLongint: Longint; override;
function GetAsVariant: variant; override;
function GetAsString: string; override;
function GetDataSize: Integer; override;
procedure GetText(var theText: string; ADisplayText: Boolean); override;
procedure SetAsFloat(AValue: Double); override;
procedure SetAsLongint(AValue: Longint); override;
procedure SetAsString(const AValue: string); override;
procedure SetVarValue(const AValue: Variant); override;
public
constructor Create(AOwner: TComponent); override;
Function CheckRange(AValue : Double) : Boolean;
property Value: Double read GetAsFloat write SetAsFloat; published
property Currency: Boolean read FCurrency write SetCurrency default False;
property MaxValue: Double read FMaxValue write FMaxValue;
property MinValue: Double read FMinValue write FMinValue;
property Precision: Longint read FPrecision write FPrecision default 15;
end;{ TNumericField }
TNumericField = class(TField)
Private
FDisplayFormat : String;
FEditFormat : String;
protected
class procedure CheckTypeSize(AValue: Longint); override;
procedure RangeError(AValue, Min, Max: Double);
procedure SetDisplayFormat(const AValue: string);
procedure SetEditFormat(const AValue: string);
function GetAsBoolean: Boolean; override;
public
constructor Create(AOwner: TComponent); override;
published
property Alignment default taRightJustify;
property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
property EditFormat: string read FEditFormat write SetEditFormat;
end; 我用的控件,一用ftCurrency就报错! With memDataSet1 Do
Begin
Close; FieldDefs.Clear; FieldDefs.Add ('Name', ftInteger, 0, True); FieldDefs.Add ('Price', ftCurrency, 10, False); CreateTable; Open;
End ; Fieldtype of Field "Price" not supported !
DefaultFieldClasses : Array [TFieldType] of TFieldClass =
( { ftUnknown} Tfield,
{ ftString} TStringField,
{ ftSmallint} TSmallIntField,
{ ftInteger} TLongintField,
{ ftWord} TWordField,
{ ftBoolean} TBooleanField,
{ ftFloat} TFloatField,
... { TFloatField } TFloatField = class(TNumericField)
private
FCurrency: Boolean;
FMaxValue : Double;
FMinValue : Double;
FPrecision : Longint;
procedure SetCurrency(const AValue: Boolean);
protected
function GetAsFloat: Double; override;
function GetAsLongint: Longint; override;
function GetAsVariant: variant; override;
function GetAsString: string; override;
function GetDataSize: Integer; override;
procedure GetText(var theText: string; ADisplayText: Boolean); override;
procedure SetAsFloat(AValue: Double); override;
procedure SetAsLongint(AValue: Longint); override;
procedure SetAsString(const AValue: string); override;
procedure SetVarValue(const AValue: Variant); override;
public
constructor Create(AOwner: TComponent); override;
Function CheckRange(AValue : Double) : Boolean;
property Value: Double read GetAsFloat write SetAsFloat; published
property Currency: Boolean read FCurrency write SetCurrency default False;
property MaxValue: Double read FMaxValue write FMaxValue;
property MinValue: Double read FMinValue write FMinValue;
property Precision: Longint read FPrecision write FPrecision default 15;
end;{ TNumericField }
TNumericField = class(TField)
Private
FDisplayFormat : String;
FEditFormat : String;
protected
class procedure CheckTypeSize(AValue: Longint); override;
procedure RangeError(AValue, Min, Max: Double);
procedure SetDisplayFormat(const AValue: string);
procedure SetEditFormat(const AValue: string);
function GetAsBoolean: Boolean; override;
public
constructor Create(AOwner: TComponent); override;
published
property Alignment default taRightJustify;
property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
property EditFormat: string read FEditFormat write SetEditFormat;
end; 我用的控件,一用ftCurrency就报错! With memDataSet1 Do
Begin
Close; FieldDefs.Clear; FieldDefs.Add ('Name', ftInteger, 0, True); FieldDefs.Add ('Price', ftCurrency, 10, False); CreateTable; Open;
End ; Fieldtype of Field "Price" not supported !
解决方案 »
- 问下Delphi的BitBtn调用的时候在Use里引用什么?
- 查询信息想在dbgrid中显示出来下面代码那错了???????!!!!!
- 一些较经典的二手书低价出售
- 如何得到一个唯一的串呢,位数尽量的少
- IdSMTP发送邮件时怎么添加附件,在线等!
- 关于FASTREPORT动态制作报表预览后的打印问题
- 数组大小不确定该如何分配内存?
- 使用了已初始化的指针,在运行时,出现acceess violation错误.
- 请问如何能使程序窗口不在任务栏里出现
- 别人帮我解决了我所提出的问题,我怎样才能把分给他呢?!
- Delphi如何用Ado连接Mysql
- 请问一下,我做了两个FORM,但是想运行的时候,run 的按钮时灰色的。
在float,double都是浮点精度,保证数据前若干位精确,当数位大时,也就损失了右侧(小数点附近)的精度。