【请教】怎样实现一个round函数? 要求有两个参数的那种,想了好久没有头绪,望高手指点…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我看了http://www.delphibbs.com/keylife/iblog_show.asp?xid=10584这篇帖子,感觉delphi的round函数有很多问题,但是我是新手,对delphi了解不多,高手帮忙一下~ 第一个参数就是要round的数,第二个参数是round的精度,可取负数,如:round(13.14,1)=13.1 round(13.14,-1)=10 http://community.csdn.net/Expert/topic/4592/4592417.xml?temp=.7033808看看僵哥的DRound函数,声明改成function DRound(Value:double;cnt:integer):double;就好了。 汇编??我要疯了~根本看不懂,谁能给翻译成delphi啊? 如果Delphi好写,我就不使用汇编了.不过其实也只是一个近似值,精确度还是比较有限的. 下面是一个C版本的------------------#include <math.h>//--------------------------------------//四舍五入//例:1.535//保留小数点后两位,做四舍五入得1.54//使用方法:Round(1.535,2)//返回值:1.54//--------------------------------------extern "C" __declspec(dllexport) double __stdcall Round(const double Value, const short int ADigit=0, const short int RoundMark=0 ){ char LocalRoundMark=RoundMark; double Result=Value; double DResult; if(ADigit>18) return Result; double DigitValue=powl(10,ADigit); if(LocalRoundMark>0)LocalRoundMark=1; if(LocalRoundMark<0)LocalRoundMark=-1; switch(LocalRoundMark) { case -1://Round Down Result*=DigitValue; if(Value<0.00)//负数 Result=ceill(Result); else Result=floorl(Result); break; case 1://Round Up Result*=DigitValue; if(Value<0.00)//负数 Result=floorl(Result); else Result=ceill(Result); break; default://Round 四舍五入 if(Value<0.00)//负数 Result-=0.5/DigitValue; else Result+=0.5/DigitValue; Result*=DigitValue; DResult=Result; if(Value<0.00) { Result=ceill(Result); DResult=Result-DResult; if(DResult>0.9999999999)Result-=1.0; } else { Result=floorl(Result); DResult=DResult-Result; if(DResult>0.9999999999)Result+=1.0; } } Result/=DigitValue; return Result;} 看出来僵哥是个高人了,但是我们的前台程序必须要用delphi写,郁闷~! mid子窗体被主窗体的空间挡住了 与C++通信的问题 fastreport好多版本呀,那个比较好用而且稳定呀?大家给点建议 ★★请问在Delphi怎样设置连接oracle的超时时间? ★★ 在线等待-100分 问几个很菜的问题(每个25分啊) 如何为DBGrid的行设置交替颜色? 程序退出问题 Delphi初级问题(高分请教). 一个小问题,谢谢大家了。 都别吵了 如何读取16(2进制)进制的文件(文件里有字母、汉字、数字等内容),怎么可以读?? ICON问题,高分相送
感觉delphi的round函数有很多问题,
但是我是新手,对delphi了解不多,
高手帮忙一下~
第二个参数是round的精度,可取负数,
如:round(13.14,1)=13.1
round(13.14,-1)=10
看看僵哥的DRound函数,声明改成
function DRound(Value:double;cnt:integer):double;就好了。
我要疯了~根本看不懂,
谁能给翻译成delphi啊?
------------------
#include <math.h>
//--------------------------------------
//四舍五入
//例:1.535
//保留小数点后两位,做四舍五入得1.54
//使用方法:Round(1.535,2)
//返回值:1.54
//--------------------------------------
extern "C" __declspec(dllexport)
double __stdcall Round(const double Value,
const short int ADigit=0,
const short int RoundMark=0
)
{
char LocalRoundMark=RoundMark;
double Result=Value;
double DResult;
if(ADigit>18)
return Result;
double DigitValue=powl(10,ADigit); if(LocalRoundMark>0)LocalRoundMark=1;
if(LocalRoundMark<0)LocalRoundMark=-1; switch(LocalRoundMark)
{
case -1://Round Down
Result*=DigitValue;
if(Value<0.00)//负数
Result=ceill(Result);
else
Result=floorl(Result);
break;
case 1://Round Up
Result*=DigitValue;
if(Value<0.00)//负数
Result=floorl(Result);
else
Result=ceill(Result);
break;
default://Round 四舍五入
if(Value<0.00)//负数
Result-=0.5/DigitValue;
else
Result+=0.5/DigitValue;
Result*=DigitValue;
DResult=Result;
if(Value<0.00)
{
Result=ceill(Result);
DResult=Result-DResult;
if(DResult>0.9999999999)Result-=1.0;
}
else
{
Result=floorl(Result);
DResult=DResult-Result;
if(DResult>0.9999999999)Result+=1.0;
}
}
Result/=DigitValue;
return Result;
}
但是我们的前台程序必须要用delphi写,
郁闷~!