# Converting String into Float

**URL:** <https://forum.katalon.com/t/converting-string-into-float/11954>\
**Category:** Miscellaneous\
**Created:** [July 10, 2018, 9:04am UTC](https://forum.katalon.com/t/converting-string-into-float/11954 "2018-07-10T09:04:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Willis\_Williandy](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/willis_williandy/32/16104_2.png) [@Willis\_Williandy](https://forum.katalon.com/u/Willis_Williandy)\
**Post date:** [July 10, 2018, 9:04am UTC](https://forum.katalon.com/t/converting-string-into-float/11954/1 "2018-07-10T09:04:55Z")

</div>

Hi all, I wanna ask you about converting string into float.

I used method parseFloat() to do it and it was worked successfully. The problem is, I get the string using ‘WebUI.getAttribute’ keyword, and maybe causes the value that I try to convert already rounded. Let me explain the example:  
- I tired to get value (which is number) from the web using ‘WebUI.getAttribute’, for example 1234567.88  
- When I tried to see the value (in string format) using println(), it give me result = 1234567.88  
- But when I tried to convert the string value into float, and print the result, it give me result = 1234568.0

this is my script  
amountReceive = WebUI.getAttribute(findTestObject(‘float/Page\_Main/input\_ucReceiveAmt\_singletxtIn’), ‘value’, FailureHandling.STOP\_ON\_FAILURE)

Float amountReceiveFloat = Float.parseFloat(amountReceive)

println(amountReceiveFloat)

I want to ask u how to keep the 2 decimal not rounded (I want the result shown me value = 1234567.88)  
Any suggestion from you would be great for me. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [July 10, 2018, 9:27am UTC](https://forum.katalon.com/t/converting-string-into-float/11954/2 "2018-07-10T09:27:16Z")

</div>

Hi Willis,

are you sure that you get correct float in first step? Because following code works as expected:

```auto
String amountReceive = "123456.78"Float amountReceiveFloat = Float.parseFloat(amountReceive)println(amountReceiveFloat)println(amountReceiveFloat.class)// console123456.78class java.lang.Float

```

---

<div class="post-metadata">

**Author:** ![Willis\_Williandy](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/willis_williandy/32/16104_2.png) [@Willis\_Williandy](https://forum.katalon.com/u/Willis_Williandy)\
**Post date:** [July 10, 2018, 10:30am UTC](https://forum.katalon.com/t/converting-string-into-float/11954/3 "2018-07-10T10:30:00Z")

</div>

Hi Marek, thanks for your response 🙂

First of all, I think the example that you gave me is little bit different with my case. I must tell that the string value was from ‘WebUI.getAttribute()’ function, not manually declare like your example.  
The case is:  
- the value that I got with ‘WebUI.getAttribute’ function is from numeric field (default 0.00), not from free text  
- when I used the getAttribute method, it gave me return type as string (I have no idea is it possible to get it on float type?)  
- so in my case, I need to parse the string type into float, and what happened is the decimal value just rounded automatically (like the example before, the string that I got = 1234567.88, but when it parsed the result = 1234568.0 )

Do you have another solution related to my case? How can I keep the decimal not rounded?

\*you can see my code below  
 ![](https://s3.amazonaws.com/katalon-forum/editor/5f/7t85dgqva7rz.png "Image: https://s3.amazonaws.com/katalon-forum/editor/5f/7t85dgqva7rz.png")

[float.png](https://s3.amazonaws.com/katalon-forum/editor/5f/7t85dgqva7rz.png)
