# Splitting a string that contains a float value

**URL:** <https://discourse.processing.org/t/splitting-a-string-that-contains-a-float-value/34065>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 11, 2021, 10:26pm UTC](https://discourse.processing.org/t/splitting-a-string-that-contains-a-float-value/34065 "2021-12-11T22:26:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![F1yin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f1yin/32/15194_2.png) [@F1yin](https://discourse.processing.org/u/F1yin)\
**Post date:** [December 11, 2021, 10:26pm UTC](https://discourse.processing.org/t/splitting-a-string-that-contains-a-float-value/34065/1 "2021-12-11T22:26:38Z")

</div>

Hi!

My goal is to use an Arduino to send processing multiple sensor readings and display them. Right now I am sending the values as a comma-separated string, and then plan on displaying each value individually by splitting the string apart.

When I send processing the test value of: 2085.46,5 my code only recognizes the second part (the 5) as a number and displays the first section (2085.46) as 0.

```auto
 inString = myPort.readStringUntil('\n');
    print(inString);
    inString = trim(inString);
    String[] splitstring = split(inString, ",");
    println(int(splitstring));

```

I am guessing this is because the first value is a float, however, I need those decimal places so I cannot have the Arduino simply convert it to an int.

I have looked at split tokens, but I honestly don’t understand how it is different nor do I know how to use it.

Lastly, as an afterthought, because I haven’t been able to try yet, can I call print(splitstring[0]); to print only the first value in the split string?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 11, 2021, 10:37pm UTC](https://discourse.processing.org/t/splitting-a-string-that-contains-a-float-value/34065/2 "2021-12-11T22:37:29Z")

</div>

> [@Using two different readStringUntil "characters"](https://discourse.processing.org/t/using-two-different-readstringuntil-characters/10769/6):
>
> The solution I gave on that link expects the Arduino C code to send the multi-data as if they were a row of tab-separated values (TSV): face_with_monocle That is, each value is followed by a \t character; except last 1, which is followed by an \n instead: nerd_face Serial.print(temperature); Serial.write('\t'); Serial.print(masse); Serial.write('\t'); Serial.print(humidite); Serial.write('\t'); Serial.print(comptage); Serial.write('\t'); Serial.println(son); // implies '\n' At the Pro…

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 11, 2021, 11:41pm UTC](https://discourse.processing.org/t/splitting-a-string-that-contains-a-float-value/34065/3 "2021-12-11T23:41:54Z")

</div>

Hello,

Try this:

```auto
void setup() 
  {
  String inString = "2085.46,5"+ "\r\n"; // From Arduino Serial.println();
  print(inString);
  inString = trim(inString);
  print(inString);
  println();
  
  String[] splitstring1 = split(inString, ",");
  println(int(splitstring1));
  
  String[] splitstring2 = split(inString, ",");
  println(float(splitstring2));
  
  String[] splitstring3 = split(inString, ",");
  println(int(float(splitstring3)));
  }

```

Output:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/580a3785a60193b353fc48a06b127e17e02bd709.png)

The above is just an example.  
I would rethink your code.

`:)`
