How to do addition of two variables contains value like 17.72 and 26.5


scenario is including following steps:

  1. Take the cost value in one variable and do same for all cost present on the page
  2. Add all the variables.
  3. Compare with total cost displayed on page.

I am not able to add the variables.

Please help me.

Sristi Sharma.

You probably use WebUI.getText() to get numbers, so you must convert String variable to float/double.

String var1 = "17.5"
String var2 = "5.555"

Double number1 = Double.parseDouble(var1)
Double number2 = Double.parseDouble(var2)

println number1 + number2

Hi @Marek_Melocik,

Can I store the result of number1 + number2 in one variable?

Thank u for your quick reply.

Of course, but the variable must be Double type (and it could be casted afterwards if you want)

Double result = number1 + number2

// if you want to have String result
String resultAsString = result.toString()

Hi @Marek_Melocik,

I have tried it and it works,

Thank You.:slight_smile: