Parse by using parseFloat()

I am trying to parse incoming data and extract two floating points by using parseFloat().
The incoming data looks like this:

an1:1.40m
an2:1.35m

And the code:

void setup() {

  Serial1.begin(115200);
  Serial.begin(115200); 

}

void loop() {

  if (Serial.available()){

      float val1 = Serial1.parseFloat();
      float val2 = Serial1.parseFloat();
      Serial.println(val1);
      Serial.println(val2);
      Serial.println("---------------------");
  }
}

The result is:

2.00
1.40
1.35
1.00
---------------------
2.00
1.40
1.00
1.35
---------------------
1.40
2.00
1.35
1.00
---------------------

I am wondering where 2.00 and 1.00 are coming from.

What do you have the Line ending set to in the Serial monitor ?

"Newline", 115200 baud.

Try no line ending

The 2.00 likely comes from the 2 in an2:1.35m

I would suggest to study Serial Input Basics to understand how to deal with Serial input

Here is demo code using the receive with end marker and parse with the strtok() examples from the serial input basics tutorial. Also the atof() function to convert strings to float data types.

const byte numChars = 15;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

float number_1;
float number_2;


void setup()
{
   Serial.begin(115200);
   Serial.println("<Arduino is ready>  Enter two float numbers separated by commas");
   Serial.println("Like 1.40,1.35");
   Serial.println("make sure Newline is enabled in serial monitor line endings");
}

void loop()
{
   recvWithEndMarker();
   if (newData)
   {
      parseData();
      newData = false;
   }
}

void recvWithEndMarker()
{
   static byte ndx = 0;
   char endMarker = '\n';
   char rc;

   while (Serial.available() > 0 && newData == false)
   {
      rc = Serial.read();
      if (rc == '\r') // ignore carriage return
      {
         return;
      }
      if (rc != endMarker)
      {
         receivedChars[ndx] = rc;
         ndx++;
         if (ndx >= numChars)
         {
            ndx = numChars - 1;
         }
      }
      else
      {
         receivedChars[ndx] = '\0'; // terminate the string
         ndx = 0;
         newData = true;
      }
   }
}

void parseData()
{
   char *strings[3]; // an array of pointers to the pieces of the above array after strtok()
   char *ptr = NULL; byte index = 0;
   ptr = strtok(receivedChars, ",");  // delimiters, semicolon
   while (ptr != NULL)
   {
      strings[index] = ptr;
      index++;
      ptr = strtok(NULL, ",");
   }

   // convert string data to numbers
   number_1 = atof(strings[0]);
   number_2 = atof(strings[1]);

   Serial.print("number 1 = ");
   Serial.print(number_1);
   Serial.print("   number 2 = ");
   Serial.print(number_2);

   Serial.println(); // blank line
}

Yes, this is another approach that requires more coding.
My initial intention was to use parseFloat(); but it seems to be difficult to realize.

Yep. A path travelled by many. "I want to do it easy" but it doesn't quite work. Eventually, you bite the bullet and do it properly per the tutorial. It also offers much more flexibility if/when your requirements evolve/change.

Yes, it seems to be a good solution.