Convert ASCII number to DEC wrong 99-100?

Since I'm a newbie in programming (havent done any in 20 years, back at school) I wanted to start a bit easy. Tried to write a function to call which should recalculate read ASCII-code from the serial monitor:

int readdata() { int number = 0; //following 2 lines are only for debugg Serial.print("Number of Bytes: "); Serial.println(Serial.available(), DEC); while(Serial.available()>0) { number=number+(Serial.read()-48)*pow(10,Serial.available()); } return(number); }

then call it by: if .... X=readdata()

This seems to work fine for values 0-99, but 100 is evaluated as 99, still reads 3 bytes. Why? Can't understand this. Rest of the numbers also seems to evaluate correct, it is only 100 that is kept at 99.

Is this what you're trying to do:

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Serial.println(readdata());
  delay(500);
}


int readdata()
 {
   byte digitsRead = 0;
   int number = 0;
   char data[5];

   if (Serial.available()) {
     digitsRead = Serial.readBytesUntil('\n', data, 4);
   }
   number = atoi(data);
   //following 2 lines are only for debugg
   Serial.print("Number of Bytes: ");
   Serial.println(digitsRead);
   return(number);
 }

The atoi() function simply converts ASCII to an integer.

Something like this?

unsigned int readdata()
{
  unsigned int number = 0;
  //following 2 lines are only for debugg
  Serial.print("Number of Bytes: ");
  Serial.println(Serial.available(), DEC);
  while(Serial.available()> 0)
  {
    number += (Serial.read()-48);
    if(Serial.available()> 0)
    {
    number *= 10;
    }
  }
  return number;
}
number=number+(Serial.read()-48)*pow(10,Serial.available());

The pow() function takes two floats and returns a float/ Which of the values you are supply is a float? What is the float that is returned used for?

The answer is that none of the arguments is a float, and you don't expect a float to be returned. So, the real question is why are you incorrectly using this function.