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

最新文章

  1. 关于angularjs中的jQuery
  2. 用:hover伪类代替js的hover事件
  3. Django的单元测试
  4. DEV winform treelist设置背景图像
  5. Libfilth(一个滤波器C库)使用
  6. linux&amp;mac下查看端口被哪个进程占用
  7. 常用的sql函数
  8. 多线程&amp;NSObject&amp;NSThread&amp;NSOperation&amp;GCD
  9. Doragon Kuesuto 1.6
  10. NIO的Selector
  11. Host绑定
  12. API和schema开发过程问题汇总
  13. iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
  14. Windows 10-限制Windows更新上传带宽
  15. Ubuntu server 16.04的安装 以及配置(服务器版)
  16. 正试图在os加载程序锁内执行托管代码。不要尝试在DllMain或映像初始化函数内运行托管代码 问题解决方法
  17. Windows 系统中的 CMD 黑窗口简单介绍
  18. 7.9 C++ STL算法
  19. php 指定页面显示所有报错
  20. JDBC架构

热门文章

  1. Mathematics:Prime Path(POJ 3126)
  2. poj 2389.Bull Math 解题报告
  3. Android 中沉浸式状态栏实现
  4. 【linux】学习3
  5. 【数据结构】book3_3 表达式求值
  6. HDU 1159 Common Subsequence --- DP入门之最长公共子序列
  7. IOS - Passbook
  8. Mysql 死锁的详细分析方法
  9. 魔法禁书目录2:回家(codevs 3024)
  10. python基础——调试