loadrunner实现浮点型数据转换成字符串
2015-11-08 13:56
429 查看
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
相关文章推荐
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I】【水题】Lottery 均分气球最小修改数
- 【C/C++学院】0826-文件重定向/键盘输入流/屏幕输出流/字符串输入输出/文件读写简单操作/字符文件读写二进制与文本差别/get与getline挖掘数据/二进制与文本差别/随机位置/多线程初级
- loadrunner通过字符串左右边界切割字符串
- 最全的Android 版本号与Level API对照表
- loadrunner以最后出现的字符串为分割符函数实现
- loadrunner实现字符串的替换
- 第9周项目2 对称矩阵压缩存储的实现与应用
- 基础动画-(1)-补间动画
- hdoj Exam 5240 (简单逻辑题)
- linux马哥 sed
- 通讯录封装实现
- ftl常用指令
- C语言中的结构体(struct)
- 马哥linux 笔记 grep和正则表达式
- 帮助文本
- linux 线程的状态及资源回收
- 从头认识java-7.1 抽象类与抽象方法
- ——黑马程序员——OC中ARC下内存管理总结
- mysql 问题
- iOS NSPredicate详解(一)