0
votes

I created a script that receives a variable from another sampler. I put the variable in a new variable (not want to mess with the source).

And I tried to double the result, the problem is that it multiply as a string and not as in math. The variable is 6, and I wanted to display 12, but it display 6.0 6.0.

Moreover, how can I save the results in a new variable?

System.out.println(" Impression Price *2 is:  " + Impression_price*2);
System.out.println(" Impression Price*2  is:  " + (Impression_price.multiply(2.0))); 

enter image description here

enter image description here

2

2 Answers

2
votes

You need to cast your args[3] which is a String to a corresponding numeric type, for example:

def Impression_price = args[3] as float

Demo:

JSR223 Numeric Operations

More information: Creating JMeter Variables in Java - The Ultimate Guide

1
votes

You need to convert String do double using Double.parseDouble, for example:

def Impression_price= Double.parseDouble(args[3]);

When you log you need to convert back to String using String.valueOf, for example:

log.info(String.valueOf(Impression_price*2));

To put a non String value you need to use vars.putObject:

vars.putObject("Impression_price_double", Impression_price *2);