loadrunner实现浮点型数据转换成字符串
2024-10-11 23:04:56
ftoa(float floatNum, char *convFloatString)
{
char new[10]; float number,dTemp,temp_val; int base, floatVal, radxFlag; char *token; char *temp; char cfloatVal[10], cBase[10]; char cfloatValx[10] = "0";
int DEBUG = 1; //Turn DEBUG OFF/ON by switch 0/1 radxFlag = 0; //Separate the number before and after the "." number = floatNum; base=number; dTemp = number-base; if(DEBUG == 1){ lr_output_message("Base Value = %f\n", number);
} sprintf(cBase, "%d", base); if(DEBUG == 1){ lr_output_message("Floating Value = %.2f\n", dTemp);
} if(dTemp == 0) //If number is a whole number then return!
{
lr_save_string(cBase, convFloatString);
return 0;
} sprintf(cfloatVal, "%.2f", dTemp); //Place the decimal point to suit your requirement. Default is 2 temp = (char *)strtok(cfloatVal, "0."); temp_val = atoi(temp); if((dTemp - 0.1) < 0) radxFlag=1;
else
radxFlag=0; if(temp_val == 0)//If decimal values equals to 0 then return!
{
strcat(cfloatVal, ".00"); //increase the number of zero to suit your requirement.
lr_save_string(cfloatVal, convFloatString);
return;
} if (radxFlag ==1)
{
strcat(cfloatValx,temp);
strcpy(temp,cfloatValx);
} if(DEBUG == 1)
{
lr_output_message("Final decimal value = %s\n", temp);
}
if(strlen(temp) == 1 && radxFlag == 0)
{
strcat(temp,cfloatValx);
//strcpy(temp,cfloatValx);
if(DEBUG == 1)
{
lr_output_message("Appending a 0 %s", temp); } } strcat(cBase, ".");
strcat(cBase, temp); if(DEBUG == 1){ lr_output_message("Final decimal value = %s\n", cfloatVal);
} if(DEBUG == 1){ lr_output_message("Final coverted floating number = %s", cBase);
} lr_save_string(cBase, convFloatString); } Action()
{ float floatNum; floatNum = 34.102;
ftoa(floatNum, "convFloatStr"); lr_output_message("Converted String = %s", lr_eval_string("{convFloatStr}")); return 0; return 0;
}
深圳湖北籍软件测试群 275212937
最新文章
- 关于angularjs中的jQuery
- 用:hover伪类代替js的hover事件
- Django的单元测试
- DEV winform treelist设置背景图像
- Libfilth(一个滤波器C库)使用
- linux&;mac下查看端口被哪个进程占用
- 常用的sql函数
- 多线程&;NSObject&;NSThread&;NSOperation&;GCD
- Doragon Kuesuto 1.6
- NIO的Selector
- Host绑定
- API和schema开发过程问题汇总
- iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
- Windows 10-限制Windows更新上传带宽
- Ubuntu server 16.04的安装 以及配置(服务器版)
- 正试图在os加载程序锁内执行托管代码。不要尝试在DllMain或映像初始化函数内运行托管代码 问题解决方法
- Windows 系统中的 CMD 黑窗口简单介绍
- 7.9 C++ STL算法
- php 指定页面显示所有报错
- JDBC架构