本文共 1127 字,大约阅读时间需要 3 分钟。
LoadRunner中有lr_save_int() 和lr_save_string() 函数,但是没有保存浮点数到变量的lr_save_float函数。《》这篇文章介绍了如何写一个这样的函数:
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=""> char formatbuf[16]; // 16 chars should be adequatesprintf( 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;}转载地址:http://qynli.baihongyu.com/