淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

win32 下解决数字四舍五入问题

上一篇 / 下一篇  2008-08-04 20:43:38 / 个人分类:loadrunner性能测试经验

 

今天在windows下用vc6 编写一程序,需要做四舍五入。
想到c99标准有round函数。可以很遗憾编译成功,LINK出错:
Linking...
run.obj : error LNK2001: unresolved external symbol _round
run.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

google的结果发现: round was added to C in the C99 standard. Microsoft still hasn't finished putting support for C99 in the compiler and round isn't in there yet.

下面函数运行成功。


#include  <stdio.h>
#include <math.h>
double Round(double num,int bit);
int main()
{
 printf("%f\n",Round(-100.5,0));
 printf("%f\n",Round(100.5,0));
 return 0;
}

//bit位数

double Round(double num,int bit)
{
 return floor( num * pow( 10 , bit ) + .5 ) / pow( 10 , bit );
}
 

 


TAG: round c99 floor pow

 

评分:0

我来说两句

Open Toolbar