Division Operation in Katalon

Need some help in operations.
Extract Premium field from UI say the amount is $976.85.
Need to Format it by removing $ symbol.
Need to divide it by 2.
Format it to 2 decimal places say 488.42(Formatted Output)
Now we need to verify if amount of this Formatted Output matches with an Object from the Object Repository say Installment1 which is the actual location where the text is displaying in UI.

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.


I assume you can extract the “Premium” field from the UI. Otherwise, we will need to see the HTML of the field.
With the “Premium” field, you can remove the dollar sign, with either a format or replace, like:

import java.text.DecimalFormat

def strPremium = ...
def premiumValue = strPremium.replace('$', '')
"divide by two as either 'float' or 'double' if really big numbers"
def resultSet = (premiumValue as float)/2.0
def strOutput = new DecimalFormat("###,##0.00").format(resultSet);

def otherOutput = ...
WebUI.comment("Your values are: ${strOutput} and ${otherOutput}")
WebUI.verifyMatch(strOutput,  otherOutput, false) 

Edit: based on @kazurayam suggestion, I changed the double quotes to single quotes. see if that works for you. I ran the code on my machine with no issue (with assumed values).

1 Like

I am getting an error on $ symbol as below:

I am hard coding premium amount for now just to test the actual behavior when the premium is extracted from UI.
It looks like Katalon is not happy with $ symbol. :wink:

Tried modifying the variables as below to remove error but got an error after execution.

1 Like

Groovy Language assigns a special meaning over “a $ character in a string enclosed with a pair of double quotation marks”:

Read the doc:


The above fragment looks odd.

How about this?

String strPremium = '$976.85'
String premiumValue = strPremium.replace('$', '')
println premiumValue        // 976.85

You should learn the syntax of string literals in Groovy language. See


1 Like