How to Untangle A String… A Method to Convert a String to Float.

In this BLOG post I’ll outline a method of converting a value in a text field into a number. So whilst I have what appears to be a number such as 43 or 43.0 or 43.67 in a text field, that is not the case. It is a string.

Numbers in Text Fields Are Strings

Numbers in Text Fields Are Strings

Whilst these apparent numbers are strings they cannot be used meaningfully in a mathematical SQL. An example of below, so what we find is that instead of adding the values, the strings concatenate.

Strings Don't Add They Concatenate

Strings Don’t Add They Concatenate

A simple trick is to multiply the numbers by 1, this converts the strings and elevates the data type to a float.

Multiply By ONE

Multiply By ONE

Share this post!

    About Idris Nujjoo

    Idris is the Product Sector Leader for InfoNet and InfoMaster and has been working for Innovyze (and its earlier incarnations) since 2001 and specifically working on InfoNet and Asset Management for the past decade.

    This entry was posted in InfoNet, InfoWorks CS, InfoWorks ICM, InfoWorks RS, InfoWorks WS. Bookmark the permalink.