码迷,mamicode.com
首页 > 其他好文 > 详细

为LoadRunner写一个lr_save_float函数

时间:2016-07-07 22:28:59      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

LoadRunner中有lr_save_int() 和lr_save_string() 函数,但是没有保存浮点数到变量的lr_save_float函数。《lr_save_float() function for LoadRunner》这篇文章介绍了如何写一个这样的函数:

http://ptfrontline.wordpress.com/2010/01/27/lr_save_float-function-for-loadrunner/

 

 

 

 

void lr_save_float(const float value, const char *param, const int decimals)
// ----------------------------------------------------------------------------
// Saves a float into a lr variable, much like lr_save_int() saves an integer
//
// Parameters:
//   value       Float value to store
//   param       Loadrunner variable name
//   decimals    Number of decimals in the result string
//
// Returns:
//   N/A
//
// Example:
//   lr_save_float(123.456, "myVar", 2);  // myVar = 123.46 (includes rounding)
//
// ----------------------------------------------------------------------------
{
  char buf[64];                              // if more>63 digits -> your problem <IMG class="wp-smiley" alt=:) src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif">
  char formatbuf[16];                        // 16 chars should be adequate

  sprintf( formatbuf, "%%.%df", decimals);   // Build the "%?.f" format string
  sprintf( buf, formatbuf, value);           // sprintf the value
  lr_save_string( buf, param);               // store in variable
}

 

 

 

 

 

 

使用例子如下:

#include "lr_save_float.h"

vuser_init()
{
 lr_save_float(123.456, "myVar", 2); 
 lr_output_message(lr_eval_string("{myVar}"));
 return 0;
}

为LoadRunner写一个lr_save_float函数

标签:

原文地址:http://www.cnblogs.com/hushaojun/p/5651682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!