jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: Want to get Integer value only from rational number
Date Fri, 10 May 2019 13:37:42 GMT

Am 10.05.19 um 14:42 schrieb Shyam Panjiyar:
> Thanks for Reply
>
> Resolved now

good to know, but please don't mix ${varname} and JSR223 Samplers. The
replacement of the variable to a String value will take place before the
script is sent to the Sampler. This will work against the caching of the
scripts, which is default now.

The " ${var} + 0.5" in my first reply is meant to emulate rounding with
the common round-up method. A value of "0.0" will do nothing and should
be left out.

The .toString() in your example is looking really strange, as it seems
to imply that you are assigning a string value to an int variable. This
is of course not the case as you are mixing ${...} with JSR 223
Samplers, which is -- I repeat -- not a good idea.

If you insist on using a JSR 223 Sampler, use the tools that they provide:

 int number =
Math.round(Double.valueOf(vars.get('FinPlanIDGen'))).toInteger();

I gave the example with jexl3 function in case you wanted to convert the
variable without a sampler or post-processor.

Felix

>
> try 
> {
>  int number = ${__jexl3((${FinPlanIDGen} + 0.0 ).intValue().toString())}; 
>  log.info("The converted integer is " + number);
>  vars.put("FinPlanIDGenerated", String.valueOf(number));
> }
> catch (Exception ex){
>     log.warn("Error in my script", ex);
>     throw ex; // elsewise JMeter will "swallow" the above exception
> }
>
> Thanks & Regards,
> Shyam Kishor Panjiyar
>  
> -----Original Message-----
> From: Shyam Panjiyar <shyam.panjiyar@5nance.com> 
> Sent: 10 May 2019 16:24
> To: 'JMeter Users List' <user@jmeter.apache.org>
> Subject: Want to get Integer value only from rational number
>
> Hi ,
>
> Could you please help with Bean Shell Sampler Script for below  requirement :-
>
> Input - String sequence from JSON Extractor as 123.0
>
> Output - String sequence in variable as 123
>
> Thanks & Regards,
> Shyam Panjiyar
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Mime
View raw message