四舍五入的简单问题 想把一个浮点型变成整型,要求是只要小数位有数,则结果都要变为大于该浮点型值的最小的整数,不想四舍五入,如14.0------1414.1------1514.4------1514.5------1514.6------1514.9------1515.0------15 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var Dest : integer; Sour : Real;如果结果想是integerDest := Round(Int(Sour+1));如果结果为Real直接用Int(Sour+1) 更正Dest := Round(Int(Sour+1));--->>Dest := Trunc(Sour+1); 日,还是没有对哦。要判断一下才行if Int(Sour)=Sour then Dest := Sourelse Dest := Int(Sour+1); uses math;function DRoundUp(Value:double;cnt:byte):double;var fTmp:double; nTmp:double; k:int64;begin Result:=Value; if cnt>18 then exit; nTmp:=Power(10.0,cnt); fTmp:=1; fTmp:=fTmp/nTmp; Result:=Result*nTmp; k:=0; asm fld qword ptr Result //__ftol begin push ebp mov ebp,esp LEA ESP,k wait fstcw word ptr [ebp-$04] wait mov al,[ebp-$03] or [ebp-$04],$00000c01 fldcw word ptr [ebp-$04] fistp qword ptr [ebp-$0c] mov [ebp-$03],al fldcw word ptr [ebp-$04] mov eax ,[ebp-$0c] mov edx,[ebp-$08] mov esp,ebp pop ebp //__ftol end push esp lea esp,k mov [esp],eax add esp,4 mov [esp],edx mov esp,ebp pop esp fild qword ptr k fstp qword ptr Result fld qword ptr nTmp fdivr qword ptr Result fstp qword ptr Result end; if Result<Value then Result:=Result+fTmp;end; 比如DRoundUP(14.0,0)RoundUP(14.1,0) Delphi本身自带的Ceil函数就是干这个的. 有必要自己写? delphi有没有直接获取当前星期几的函数? ExpressQuantumGrid和ehlib这两个控件该如何取舍?它们有什么优缺点? 两个AdoQuery连接同一个表遇到的问题奇怪问题 这个sql语句里的decode是什么意思啊? 在DELPHI中怎样将十六进制数转化为十进制数? 一个关于dbedit的问题 界面问题 哪位大虾写过P2P软件? 好久没来了,大家还好吧!问一个关于三层结构的问题? 关于Tstringgrid的问题? ADOQuery数据怎么不能自动更新.......顺便放分! 如何在程序中实现自动拨号(ADSL)
Dest : integer;
Sour : Real;如果结果想是integer
Dest := Round(Int(Sour+1));如果结果为Real
直接用
Int(Sour+1)
Dest := Round(Int(Sour+1));
--->>
Dest := Trunc(Sour+1);
Dest := Sour
else
Dest := Int(Sour+1);
math;function DRoundUp(Value:double;cnt:byte):double;
var
fTmp:double;
nTmp:double;
k:int64;
begin
Result:=Value;
if cnt>18 then exit;
nTmp:=Power(10.0,cnt);
fTmp:=1;
fTmp:=fTmp/nTmp;
Result:=Result*nTmp;
k:=0;
asm
fld qword ptr Result
//__ftol begin
push ebp
mov ebp,esp
LEA ESP,k
wait
fstcw word ptr [ebp-$04]
wait
mov al,[ebp-$03]
or [ebp-$04],$00000c01
fldcw word ptr [ebp-$04]
fistp qword ptr [ebp-$0c]
mov [ebp-$03],al
fldcw word ptr [ebp-$04]
mov eax ,[ebp-$0c]
mov edx,[ebp-$08]
mov esp,ebp
pop ebp
//__ftol end
push esp
lea esp,k
mov [esp],eax
add esp,4
mov [esp],edx
mov esp,ebp
pop esp
fild qword ptr k
fstp qword ptr Result
fld qword ptr nTmp
fdivr qword ptr Result
fstp qword ptr Result
end;
if Result<Value then Result:=Result+fTmp;
end;
DRoundUP(14.0,0)
RoundUP(14.1,0)