最近在编程时遇到一个奇怪的现象请看下面的例子:
1>
procedure TForm1.BitBtn1Click(Sender: TObject);
var x, y : extended;
begin
x :=100.123;
y :=strtofloat(formatfloat('0.###',1000.12345678));
if x =y then showmessage(floattostr(x)+'='+floattostr(y))
else
showmessage(floattostr(x)+'<>'+floattostr(y));
end;
运行后的结果是: 100.123<>100.123 ,请问这是怎么回事.请解释其原因.2>
另外Round函数是将一个实数四舍五入转换为一个64位整数.我用下面的代码求出来的值却是 100 而不是101. 请各位大侠
showmessage(floattostr(round(100.5)));3>
在DELPHI中,怎样将一个实数四舍五入到小数点后2位.以上第一种方法除外.
1>
procedure TForm1.BitBtn1Click(Sender: TObject);
var x, y : extended;
begin
x :=100.123;
y :=strtofloat(formatfloat('0.###',1000.12345678));
if x =y then showmessage(floattostr(x)+'='+floattostr(y))
else
showmessage(floattostr(x)+'<>'+floattostr(y));
end;
运行后的结果是: 100.123<>100.123 ,请问这是怎么回事.请解释其原因.2>
另外Round函数是将一个实数四舍五入转换为一个64位整数.我用下面的代码求出来的值却是 100 而不是101. 请各位大侠
showmessage(floattostr(round(100.5)));3>
在DELPHI中,怎样将一个实数四舍五入到小数点后2位.以上第一种方法除外.
解决方案 »
- fastreport怎么连续打印多张
- 請教
- 200分求PsFRExportFilters(fastreport导出附加控件),能用马上给分
- 为什么我用将字段属性设为fkLookup,KeyFields设为两个字段用分号(XX;XX)割开时,总是提示XX;XX找不到?
- VC中有一个函数原型XXX,在delphi中该怎么样声明 并 调用?
- HELP!请各位来看看!这个程序的错误信息是怎样引起的,应怎样解决!
- 我的自定义控件中用到了滚动条,我想设定它的ctl3d属性,怎么做?
- 数据库问题:简单的连接并描述过程(内细说)
- 怎样在注册表中搜索某一主键值(或者列出某一主键值下所以子键值的内容)
- 哪位大虾知道 怎么解决"套打"问题?
- 事务中出错,竟然导致系统死机!各位大侠,请问如何解决?在线等待
- 一个小小的问题,大量散分,来者有分。
应该是那样
2,
也是对的,round四舍五入,trunc才能得出100
3,
我不知道
对于XXX.5的情况,整数部分是奇数,那么会Round Up,偶数会Round Down,例如:
x:= Round(17.5) = x = 18 x:= Round(12.5) = x = 12
请使用下面的函数代替Round:
function DoRound(Value: Extended): Int64; procedure Set8087CW(NewCW: Word);
asm
MOV Default8087CW,AX
FNCLEX
FLDCW Default8087CW
end;const
RoundUpCW = $1B32;
var
OldCW : Word;
begin
OldCW := Default8087CW;
try
Set8087CW(RoundUpCW);
Result := Round(Value);
finally
Set8087CW(OldCW);
end;
end;〈超级猛料〉
这是什么^_^多了一个零2。四舍六入五看前
3。FormatFloat
应该用a1-a2>0.0000000001的方式进行比较,这是delphi自身的处理方式
2:
round(100.5)=100
round(100.51)=101