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)));
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:
More information: Creating JMeter Variables in Java - The Ultimate Guide
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);
Related
I'm trying to compare to strings in a function to be able to do stuff if it's true. However, for some reason the two strings I'm comparing are never equal to eachother.
I am creating a new string in a function, getting data from a Json and then comparing that string with another string in another class. This doesn't work for some reason. The Debug shows that both strings are equal, but the if-statement returns false.
I created two other string variables (hello & hello2) with the same value ("Hello") and this time it's comparing correctly.
Check the images below. What am I doing wrong?
As you can see in the console, both strings have the same value:
Image 1. Here's where I create the string (zoneId).
Image 2. Further down in the same function, same for-loop.
Here's where I'm trying to compare the string created in this function with another string from another class.
Image 3. As you can see in the console it's looping through the jsonArray. But it's returning false even though it's clear that both strings have the same value.
Image 4 and 5. Here I am testing with two other strings inside the function and they are working fine.
Does it has something to do calling a string from another class?
Here's how my other string in userInfo is set up:
public string userID { get; private set; }
In Image 3, is there an additional space before the second 2?
How are you processing Main.Instance.userInfo.zoneID?
You need to use string.Equals for string comparison instead of operator == or !=.
Are string.Equals() and == operator really same?
I'm using the Apache POI framework for parsing large Excel spreadsheets. I'm using this example code as a guide: XLSX2CSV.java
I'm finding that cells that contain just numbers are implicitly being treated as numeric fields, while I wanted them to be treated always as strings. So rather than getting 1.00E+13 (which I'm currently getting) I'll get the original string value: 10020300000000.
The example code uses a XSSFSheetXMLHandler which is passed an instance of DataFormatter. Is there a way to use that DataFormatter to treat all cells as strings?
Or as an alternative: in the implementation of the interface SheetContentsHandler.cell method there is string value that is the cellReference. Is there a way to convert a cellReference into an index so that I can use the SharedStringsTable.getEntryAt(int idx) method to read directly from the strings table?
To reproduce the issue, just run the sample code on an xlsx file of your choice with a number like the one in my example above.
UPDATE: It turns out that the string value I get seems to match what you would see in Excel. So I guess that's going to be "good enough" generally. I'd expect the data I'm sent to "look right" and therefore it'll get parsed correctly. However, I'm sure there will be mistakes and in those cases it'd be nice if I could get at the raw string value using the streaming API.
To resolve this issue I created my own class based on XSSFSheetXMLHandler
I copied that class, renamed it and then in the endElement method I changed this part of the code which is formatting the raw string:
case NUMBER:
String n = value.toString();
if (this.formatString != null && n.length() > 0)
thisStr = formatter.formatRawCellContents(Double.parseDouble(n), this.formatIndex, this.formatString);
else
thisStr = n;
break;
I changed it so that it would not format the raw string:
case NUMBER:
thisStr = value.toString();
break;
Now every number in my spreadsheet has its raw value returned rather than a formatted version.
If for instance I have a variable xa=2, and then I construct a string by joining 'x' and 'a', how can I make this new string have the value 2?
xa=2;
var=strcat('x','a');
The result of this is var=xa, but what I want is var=2.
Thank you
Use eval():
var = eval(strcat('x','a'));
It will "evaluate" the string 'xa' and translate it to the value of the variable xa.
Source : MATLAB documentation
Visual Studio is giving me the following error when I submit and store in the database.
"string must be exactly one character long"
to try to resolve tried this but without success:
cmd.Parameters.Add("#nomeEmpresa", OleDb.OleDbType.Integer).Value = Convert.ToChar(cbxEmpresa.Text)
cmd.Parameters.Add("#nomeContacto", OleDb.OleDbType.Integer).Value = Convert.ToChar(txtNomeContacto.Text)
cmd.Parameters.Add("#apelidoContacto", OleDb.OleDbType.Integer).Value = Convert.ToChar(txtApelidoContacto.Text)
cmd.Parameters.Add("#funcao", OleDb.OleDbType.Integer).Value = Convert.ToChar(txtFuncao.Text)
how can I solve this problem?
If you look at the documentation of Convert.ToChar you could read
Converts the first character of a specified string to a Unicode
character. Namespace: System Assembly: mscorlib (in mscorlib.dll)
Syntax
public static char ToChar( string value )
valueType: System.String
A string of length 1.
That's the reason of your error.
However your code seems to be incorrect. If you want to pass Integer values types by your user to your sql you need to convert your input using something like Int32.TryParse(textbox.text)
Instead if you want to pass string values you need to change your parameter type to SqlDbType.NVarChar.
Convert.ToChar(string) requires that the string only contain a single character. You need to gaurrantee this for each of the strings before you call it, or manually select the first character from the string, or something similar.
Docs for Convert.ToChar(string), throws FormatException "The length of value is not 1."
http://msdn.microsoft.com/en-us/library/5f3ew98y(v=vs.110).aspx
I'm building a calculator application, and I have a Form, with a TextBox called txtVisor, that has the property NumbersOnly = true. I want to get the content of it(that I already know: txtVisor.Text) and convert it into a Integer, to do multiply it by 12, then convert the result into a String to set the txtVisor.Text as the result of the operation. How could I do this?
PS: I'm using NSBasic 7.0
txtVisor.Text = cstr( cint(txtVisor.Text)*12 )
The current version is NS Basic/CE 8, which will make your life much easier when it comes time to deploy your app.