# Gateway Script How to use split, numberFormat, tofloat?

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303>\
**Category:** General Discussion\
**Created:** [August 3, 2015, 8:49pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303 "2015-08-03T20:49:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [August 3, 2015, 8:49pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/1 "2015-08-03T20:49:32Z")

</div>

Hello,  
I currently have an expression tag that is garbing specific information from a comma delimited string.  
The expression of the tag is too long and prevents a gateway script from using the correct value, I need to do conversion withing the gateway script.

What libraries do I need to expose to be able to do the following?  
numberFormat(tofloat(split({[.]CheeseScale},",")[2,0],0),"#0.00")

right now I’m getting.

Traceback (most recent call last):  
File “TagChangeScript:Farmdale/CheeseScaleScript”, line 29, in   
NameError: name ‘split’ is not defined  
NameError: name ‘numberFormat’ is not defined.  
NameError: name ‘tofloat’ is not defined.

---

<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:** [August 3, 2015, 8:58pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/2 "2015-08-03T20:58:43Z")

</div>

At the moment it looks like your trying to use a mix of python and expression languages…

Can we get a sample of what the data coming in would look like?

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [August 3, 2015, 9:07pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/3 "2015-08-03T21:07:00Z")

</div>

Here is the string.  
3,158,42.80,2163.70,2,1,CH001BK,20150304

---

<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:** [August 3, 2015, 9:07pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/4 "2015-08-03T21:07:57Z")

</div>

so the value will always be the third item?

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [August 3, 2015, 9:15pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/5 "2015-08-03T21:15:18Z")

</div>

Yes

---

<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:** [August 3, 2015, 9:16pm UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/6 "2015-08-03T21:16:11Z")

</div>

Gotcha. I’m on my way home, but should have something for you later on this evening. 🙂

---

<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:** [August 4, 2015, 12:14am UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/7 "2015-08-04T00:14:47Z")

</div>

My connection back to work is flaky tonight, but QPython on my Kindle to the rescue!  
Here’s a python example that should give you some ideas.

[code]def find\_nth\_character(str1, substr, n):  
pos = -1  
for x in xrange(n):  
pos = str1.find(substr, pos+1)  
if pos == -1:  
return None  
return pos

dataIn=‘3,158,42.80,2163.70,2,1,CH001BK,20150304’  
subStart = find\_nth\_character(dataIn,’,’,2) + 1  
subEnd = find\_nth\_character(dataIn,’,’,3)

print dataIn[subStart:subEnd][/code]

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/956c6ff76a8bf22cb620aa012d9fd799799ceaa2.png)

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [August 4, 2015, 4:24am UTC](https://forum.inductiveautomation.com/t/gateway-script-how-to-use-split-numberformat-tofloat/10303/8 "2015-08-04T04:24:04Z")

</div>

Thank you Jordan,  
I wanted to use the build in function of python within the gateway script and here is the approached I’m taking

==============  
import string  
strDataIn=‘3,158,42.80,2163.70,2,1,CH001BK,20150304’  
strDataOut = string.split(strDataIn,",")[2:3]  
strWeight = string.join(strDataOut)

once gain thank you.
