Write a lr_save_float function for LoadRunner

Source: Internet
Author: User

There are Lr_save_int () and lr_save_string () functions in LoadRunner, but there is no lr_save_float function to save floating-point numbers to variables. "Lr_save_float () function for LoadRunner" This article describes how to write a function like this:

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 as 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
Char formatbuf[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
}

Examples of use are as follows:

#include "Lr_save_float.h"

Vuser_init ()
{
Lr_save_float (123.456, "MyVar", 2);
Lr_output_message (Lr_eval_string ("{MyVar}"));
return 0;
}

Write a lr_save_float function for LoadRunner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.