首页 > 其他 > 详细

为LoadRunner写一个lr_save_float函数

时间:2016-07-07 22:26:01      阅读:288      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!