# Dataset string to float

**URL:** <https://forum.inductiveautomation.com/t/dataset-string-to-float/5519>\
**Category:** Ignition\
**Created:** [December 3, 2012, 4:40pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519 "2012-12-03T16:40:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 3, 2012, 4:40pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/1 "2012-12-03T16:40:04Z")

</div>

We are collecting data from a scale using the TCP driver, which gives us data back in the Message tag, and it comes back as a string that we have to parse. Once it’s parsed we end up with a few columns, and one of them is actual weight data, but it is still a String. We would like to Total, avg, chart, etc. that data. It works great in the Reporting module, but we can’t seem to get that data from a string, to a float so we can chart it. How would we go about taking a column in a dataset that is String (3.49g, 3.61g, 3.50g, etc…) and turn it into a float in a new dataset so it can be charted? (we don’t need the ‘g’ that comes out with the parsing).  
Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 3, 2012, 4:46pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/2 "2012-12-03T16:46:53Z")

</div>

[code]\>\>\> s = '3.95g'

> > > s = s.replace('g', '')  
> > > print float(s)  
> > > 3.95[/code]

---

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 4, 2012, 9:37pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/3 "2012-12-04T21:37:52Z")

</div>

Kevin,  
I can see that for an individual cell, but how would we apply that to a whole column within a dataset? We want to have a new dataset with a column of floats instead of strings, not just one cell.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 4, 2012, 9:45pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/4 "2012-12-04T21:45:14Z")

</div>

Can you apply the conversion during your parsing, before you build the dataset?

---

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 8, 2012, 8:15pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/5 "2012-12-08T20:15:17Z")

</div>

Kevin, It isn’t possible to apply the code during parsing, (as far as I know). But, we did find a solution that you and other users may/may not find useful; what we did is develop a query and perform a math function on that query, which would have normally (without the math function) returned a string dataset, but with the math function it returns a float dataset. See below:

SELECT ((SUBSTR(Message,9,11)) - 0)AS ‘L1 ABOVE WT’  
FROM SCALE1\_DATA  
order by t\_stamp DESC  
limit 10

With the “- 0” as part of the query it subtracts zero (the math function) without actually changing the number and outputs the results as float data, which can then be summed, averaged, etc.

Hope this helps anybody who query’s and needs to seperate numbers from a string.

---

<div class="post-metadata">

**Author:** ![Michael.Stofan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.stofan/32/3342_2.png) [@Michael.Stofan](https://forum.inductiveautomation.com/u/Michael.Stofan)\
**Post date:** [December 11, 2012, 12:05am UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/6 "2012-12-11T00:05:31Z")

</div>

Cool solution, thanks for posting it up!

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [December 11, 2012, 6:16am UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/7 "2012-12-11T06:16:18Z")

</div>

Scott - is your example for MySQL?

---

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 18, 2012, 3:36pm UTC](https://forum.inductiveautomation.com/t/dataset-string-to-float/5519/8 "2012-12-18T15:36:12Z")

</div>

Nathan,  
Yes, this is in MySQL.
