# Division Operation in Katalon

**URL:** <https://forum.katalon.com/t/division-operation-in-katalon/134981>\
**Category:** Miscellaneous\
**Created:** [June 17, 2024, 10:27pm UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981 "2024-06-17T22:27:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsingh1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dsingh1/32/23870_2.png) [@dsingh1](https://forum.katalon.com/u/dsingh1)\
**Post date:** [June 17, 2024, 10:27pm UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/1 "2024-06-17T22:27:49Z")

</div>

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.  
976.85/2=488.425  
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.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [June 17, 2024, 10:27pm UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/2 "2024-06-17T22:27:49Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [June 18, 2024, 12:12am UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/3 "2024-06-18T00:12:00Z")

</div>

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:

```auto
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).

> <https://stackoverflow.com/questions/58969993/fixed-decimal-places-java-groovy>

> [@Fighting with MAP formatting](http://forum.katalon.com/t/fighting-with-map-formatting/132746/5):
>
> Just for your information, see the following script import java.text.DecimalFormat Map\<String, Integer\> m = ["OnLoad":0] println "${m.get("OnLoad")}, ${m.get("OnLoad").getClass().getName()}" m.put("OnLoad", 1.2345) println "${m.get("OnLoad")}, ${m.get("OnLoad").getClass().getName()}" String s = new DecimalFormat("#,###,###,##0").format(m.get("OnLoad")); println "${s}, ${s.getClass().getName()}" and the output from it. 2024-06-05 19:50:51.587 INFO c.k.katalon.core.main.TestCaseExecutor - -…

---

<div class="post-metadata">

**Author:** ![dsingh1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dsingh1/32/23870_2.png) [@dsingh1](https://forum.katalon.com/u/dsingh1)\
**Post date:** [June 18, 2024, 4:09am UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/4 "2024-06-18T04:09:55Z")

</div>

Hi,  
I am getting an error on $ symbol as below:

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/6/8/685679a825268934c20cff3ffc57ef6dfbc4f908.png)

Note:  
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. 😉

Tried modifying the variables as below to remove error but got an error after execution.  
 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/b/a/baec3e0edb9e81e96fee96d2090b8ab546b4babc.png)

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/e/b/eb526850a3644ec15c7ef6a131d0ed73bb0a16d6.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 18, 2024, 2:08pm UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/5 "2024-06-18T14:08:05Z")

</div>

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

Read the doc:

[https://docs.groovy-lang.org/latest/html/documentation/index.html#\_string\_interpolation](https://docs.groovy-lang.org/latest/html/documentation/index.html#_string_interpolation)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 18, 2024, 9:26pm UTC](https://forum.katalon.com/t/division-operation-in-katalon/134981/6 "2024-06-18T21:26:45Z")

</div>

[https://europe1.discourse-cdn.com/katalon/uploads/default/uploads/default/original/3X/b/a/baec3e0edb9e81e96fee96d2090b8ab546b4babc.png](https://europe1.discourse-cdn.com/katalon/uploads/default/uploads/default/original/3X/b/a/baec3e0edb9e81e96fee96d2090b8ab546b4babc.png)

The above fragment looks odd.

How about this?

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

```

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

> **[The Apache Groovy programming language - Syntax](https://groovy-lang.org/syntax.html#all-strings)**
