# Convert string to Float

**URL:** <https://forum.universal-robots.com/t/convert-string-to-float/975>\
**Category:** URScript\
**Created:** [July 14, 2017, 11:37am UTC](https://forum.universal-robots.com/t/convert-string-to-float/975 "2017-07-14T11:37:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon35523963](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@anon35523963](https://forum.universal-robots.com/u/anon35523963)\
**Post date:** [July 14, 2017, 11:38am UTC](https://forum.universal-robots.com/t/convert-string-to-float/975/1 "2017-07-14T11:38:00Z")

</div>

Hello Everyone!  
I didn’t find such topic. So I decide to to set up a topic.

I couldn’t find at script manual the function to convert string to float.  
I tried to use the Python function

a = "52525238,27337273,83495772"  
float(a) or int(a)

but it didn’t work. Can somebody help me with this?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [July 14, 2017, 11:42am UTC](https://forum.universal-robots.com/t/convert-string-to-float/975/2 "2017-07-14T11:42:07Z")

</div>

In URScript, you cannot convert string-based (ASCII) numerics to URScript numbers.  
A workaround could be to send the string to an external server, and get the converted numeric back.  
E.g. like the XML-RPC Math sample in the samples topic.

If you receive the floats over a socket, the option however would be to use the `socket_read_ascii_float()` script code, which is the only case where strings can be converted into floats.  
However this require that the string is formatted like `"(1.23, 2.34, 3.45)"`

---

<div class="post-metadata">

**Author:** ![anon35523963](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@anon35523963](https://forum.universal-robots.com/u/anon35523963)\
**Post date:** [July 14, 2017, 12:29pm UTC](https://forum.universal-robots.com/t/convert-string-to-float/975/3 "2017-07-14T12:29:59Z")

</div>

Hi Jacob,

Thank You for answer. I receive over a socket such string “52525238,27337273,83495772,”. The _socket\_read\_ascii\_float()_ didn’t work. Worked only _socket\_read\_string()_

---

<div class="post-metadata">

**Author:** ![roman.reiner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roman.reiner/32/1294_2.png) [@roman.reiner](https://forum.universal-robots.com/u/roman.reiner)\
**Post date:** [July 14, 2017, 12:40pm UTC](https://forum.universal-robots.com/t/convert-string-to-float/975/4 "2017-07-14T12:40:33Z")

</div>

Make sure you’re doing this the data format for “socket\_read"ascii\_float” in Polyscope is strict.

 ![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/8c00eea70ac23c208941f64e97e615475d16481c.png)

---

<div class="post-metadata">

**Author:** ![anon35523963](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@anon35523963](https://forum.universal-robots.com/u/anon35523963)\
**Post date:** [July 18, 2017, 1:14pm UTC](https://forum.universal-robots.com/t/convert-string-to-float/975/5 "2017-07-18T13:14:46Z")

</div>

I will try check the format if it wasn’t wrong, thanks.
