Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Established Member.. DamienCurrier
Established Member..
1883 views

Convert a float to a string parameter in VuGen script?

Jump to solution

Hello,

I've been struggling with this all afternoon. I have a 16 digit number that for each iteration I need to add 1 to and then convert that into a string parameter for use later on. But I'm not able to figure out how to do this with the function reference library in VuGen.  Here's an example of what I'm trying to do:

float flt = atof("1111119999999999");
float flt2 = flt + 1;
const char* chr;
sprintf(chr,"%.0f",flt2);

lr_save_string(chr,"OutParm");

lr_vuser_status_message("Output: %s",lr_eval_string("{outParm}"));

I'm hoping to get:
Output: 1111120000000000

But instead it's throwing error messages.
Thoughts?

0 Likes
1 Solution

Accepted Solutions
Absent Member.. Craig_Drummond Absent Member..
Absent Member..

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

there are more problems that just those two.

 

1) define your string  as char chr[16];

 

2) in my testing atof does not give you the value that you want.  You can see what I mean by pasting in the example code from the help file in VuGen 11.52

 

    float x;
    char *= "7.2339";

    x = atof(s);
    /* The %.2f formatting string limits the output to 2 decimal places */
    lr_output_message("%.2f", x);

 

According to the help the output should be 7.23 but when run in VuGen the output is 105132216.00  So there is a problem with the atof function.  I can check to see if it is resolved in VuGen 12.01 but I don't think it has.

 

3) you have to many digits.  VuGen will only be able to process the first 10 digits before you will get a memory exception.

 

I changed your code to the following and it runs with no error:

 

Action()
{
    //1111119999999999
    float flt = 1111119999;
    float flt2 = flt + 1;
    char chr[16];

    sprintf(chr,"%.0f",flt2);
    
    lr_save_string(chr,"OutParm");
    
    lr_output_message("%.0f", flt);
    lr_output_message("%.0f", flt2);
    lr_output_message("output: %s", lr_eval_string("{OutParm}"));
    
    return 0;
}

 

Craig Drummond

HP SW Premier Support, Technical Account Manger - ALM Products

 

View solution in original post

0 Likes
7 Replies
IgorM Honored Contributor.
Honored Contributor.

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

Issue 1: allocate memory for "chr".

Issue 2: change "outParam" to "OutParam" in last line.

 

 

Igor Markov
R&D Manager, Performance Engineering Core
0 Likes
Absent Member.. Craig_Drummond Absent Member..
Absent Member..

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

there are more problems that just those two.

 

1) define your string  as char chr[16];

 

2) in my testing atof does not give you the value that you want.  You can see what I mean by pasting in the example code from the help file in VuGen 11.52

 

    float x;
    char *= "7.2339";

    x = atof(s);
    /* The %.2f formatting string limits the output to 2 decimal places */
    lr_output_message("%.2f", x);

 

According to the help the output should be 7.23 but when run in VuGen the output is 105132216.00  So there is a problem with the atof function.  I can check to see if it is resolved in VuGen 12.01 but I don't think it has.

 

3) you have to many digits.  VuGen will only be able to process the first 10 digits before you will get a memory exception.

 

I changed your code to the following and it runs with no error:

 

Action()
{
    //1111119999999999
    float flt = 1111119999;
    float flt2 = flt + 1;
    char chr[16];

    sprintf(chr,"%.0f",flt2);
    
    lr_save_string(chr,"OutParm");
    
    lr_output_message("%.0f", flt);
    lr_output_message("%.0f", flt2);
    lr_output_message("output: %s", lr_eval_string("{OutParm}"));
    
    return 0;
}

 

Craig Drummond

HP SW Premier Support, Technical Account Manger - ALM Products

 

View solution in original post

0 Likes
Absent Member.. Craig_Drummond Absent Member..
Absent Member..

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

I checked Vugen 12.01 and the atof function is not producing the same result as 11.52 but 12.01 is still wrong.  I will open a case to have HP look at why.

 

Craig

0 Likes
Speedmaster Outstanding Contributor.
Outstanding Contributor.

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

Craig, did you ever get an update from HP on this?

 

Thanks,

Chris

0 Likes
Absent Member.. Craig_Drummond Absent Member..
Absent Member..

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

Unfortunately no, I have not been able to open any cases on the support site because of the changes they made recently.

 

Craig

0 Likes
IgorM Honored Contributor.
Honored Contributor.

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

I'll make sure to check this and have it fixed.

Igor Markov
R&D Manager, Performance Engineering Core
vvelichko Absent Member.
Absent Member.

Re: Convert a float to a string parameter in VuGen script?

Jump to solution

Hi All,

 

As it's described in Functional Reference example, you should add the following text:
double atof(const char *string) before the Action ().

 

double atof( const char *string); /* Explicit declaration */
vuser_init() {
     float x;
     char *s = "7.2339 by these hilts or I am a villain else";
     x = atof(s);
     /* The %.2f formatting string limits the output to 2 decimal places */
     lr_output_message("%.2f", x);
     return 0;
}

 

That fixes the problem

 

Thanks,

Vladimir,
LoadRunner QA Engineer

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.