为LoadRunner写一个lr_save_float函数
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;
}