# Troubles turning unicode into float

**URL:** <https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256>\
**Category:** Ignition\
**Created:** [February 12, 2025, 4:40pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256 "2025-02-12T16:40:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephanie\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephanie\_Aguiar](https://forum.inductiveautomation.com/u/Stephanie_Aguiar)\
**Post date:** [February 12, 2025, 4:40pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/1 "2025-02-12T16:40:20Z")

</div>

I am trying to turn my unicode into a float but I dont know why i cant convert it. I have already tried to use .strip() but thats isnt working so I'm not sure what else I can do.

 ![Screenshot 2025-02-12 082156](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3e8024faf8c799a134bc80c025113c0567184a3f.jpeg)

```python
<type 'unicode'>
<type 'float'>
<type 'unicode'>
 

1
<type 'unicode'>
 

1
<type 'unicode'>
0.00025
0.00025
1
<type 'unicode'>
0.00025
0.00025
1
<type 'unicode'>
0.00100
0.00100
1
<type 'unicode'>
0.00500
0.00500
1
<type 'unicode'>
0.00025
0.00025
1
<type 'unicode'>
 

1
<type 'unicode'>
 

<type 'unicode'>
 

<type 'unicode'>
 

<type 'unicode'>
 

<type 'unicode'>
 

<type 'unicode'>
 

<type 'unicode'>
 

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [February 12, 2025, 4:49pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/2 "2025-02-12T16:49:42Z")

</div>

Post code, not pictures of code, see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

It makes it faster/easier for others to test your code and provide solutions. You can edit your post by clicking the edit icon (pencil icon) on the bottom right of your post.

Moving on from that, it appears that some of your values are returning blank strings? Add something to catch when the values are blank strings and either supply a default value or null.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 12, 2025, 4:49pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/3 "2025-02-12T16:49:58Z")

</div>

An empty string is not valid for conversion to any number.

---

<div class="post-metadata">

**Author:** ![Stephanie\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephanie\_Aguiar](https://forum.inductiveautomation.com/u/Stephanie_Aguiar)\
**Post date:** [February 12, 2025, 5:11pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/4 "2025-02-12T17:11:20Z")

</div>

```python
t_stamp = system.date.now()
part_number = system.tag.readBlocking("[default]T2_Renishaw/RESDATA_Table_Results[0,7]")[0].value

for i in range(15):
    base_path = "[default]T2_Renishaw/RESDATA_Table_Results["
    path = base_path + str(i) + ",0]"
    feature_value = system.tag.readBlocking(str(path))[0].value
    
    path2 = base_path + str(i) + ",2]"
    actual_value = system.tag.readBlocking(str(path2))[0].value
    
    path3 = base_path + str(i) + ",1]"
    type_value = system.tag.readBlocking(str(path3))[0].value
    
    path4 = base_path + str(i) + ",4]"
    tolerance_value = system.tag.readBlocking(str(path4))[0].value
    
    path5 = base_path + str(i) + ",3]"
    nominal_value = system.tag.readBlocking(str(path5))[0].value
    
    tolerance_value = float(tolerance_value)
    
    if feature_value != " " and actual_value != " " and type_value != " ":
        params2 = {"t_stamp":t_stamp,
                    "part_number":part_number,
                    "feature_name":feature_value,
                    "actual":actual_value,
                    "feature_type":type_value,
                    "tolerance":tolerance_value}
        system.db.runNamedQuery("Renishaw Tops 2 Insert Feature and Actual Values", params2)

```

---

<div class="post-metadata">

**Author:** ![Stephanie\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephanie\_Aguiar](https://forum.inductiveautomation.com/u/Stephanie_Aguiar)\
**Post date:** [February 12, 2025, 5:13pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/5 "2025-02-12T17:13:17Z")

</div>

its weird because if i put print tolerance\_value , there is a value 0.0035. and that is a unicode because when I do print type(tolerance\_value) is says unicode

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 12, 2025, 5:16pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/6 "2025-02-12T17:16:14Z")

</div>

You really shouldn't be using the `tolerance_value` variable as two different data types. Use a different variable name for either float or string, and see if that shows any other buggy assumptions.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [February 12, 2025, 5:37pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/7 "2025-02-12T17:37:52Z")

</div>

> [@Stephanie\_Aguiar](#):
>
> if i put print tolerance\_value , there is a value 0.0035

If you put a print on line 25, that's the result you get?

If i'm not mistaken, if you look at my badly edited screenshot, it seems that your fourth and fifth print statements are printing empty lines because the value is empty and the next line is trying to convert nothing into a Float

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d48b325482e8bde8ac6c8998d033e37ebd8f3b9.jpeg)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 12, 2025, 6:46pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/8 "2025-02-12T18:46:14Z")

</div>

- If you replace print with repr(), you can see what your incoming values really are.
- Assuming it's a blank string what do you want your value to be? Or, should it skip that iteration?

---

<div class="post-metadata">

**Author:** ![Stephanie\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephanie\_Aguiar](https://forum.inductiveautomation.com/u/Stephanie_Aguiar)\
**Post date:** [February 12, 2025, 7:16pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/9 "2025-02-12T19:16:44Z")

</div>

oh i see! and yes, if there is a blank value it should skip it

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 12, 2025, 7:21pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/10 "2025-02-12T19:21:37Z")

</div>

One thing I'm noticing, is this all coming from a dataset tag? If so, there is a lot more efficient way to process this.

You may also want to consider using system.db.runPrepUpdate if you are trying to do a bulk insert.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [February 13, 2025, 3:31pm UTC](https://forum.inductiveautomation.com/t/troubles-turning-unicode-into-float/102256/11 "2025-02-13T15:31:19Z")

</div>

Try this, for performances, but mostly for sanity:

```python
t_stamp = system.date.now()
path = "[default]T2_Renishaw/RESDATA_Table_Results"
data = system.tag.readBlocking([path])[0].value
part_number = data[0][7]

for row in data:
    feature_value = row[0]
    type_value = row[1]
    actual_value = row[2]
    nominal_value = row[3]
    tolerance_value = float(row[4])

    if feature_value != " " and actual_value != " " and type_value != " ":
        params2 = {"t_stamp":t_stamp,
                    "part_number":part_number,
                    "feature_name":feature_value,
                    "actual":actual_value,
                    "feature_type":type_value,
                    "tolerance":tolerance_value}
        system.db.runNamedQuery("Renishaw Tops 2 Insert Feature and Actual Values", params2)

```

This is strictly equivalent to your inital code, so it won't fix the issue, but it's a saner base to work on.

Is the tag you're reading from a database tag ?  
If that's the case, any reason you're not just pulling data from the db directly instead of going through an intermediary tag ?
