Problem on dividing, weird result

if (Serial.available() > 1) {
    delay(100);  //Mesaj gelsin
    lcd.clear();  //lcd temizle
    lcd.setCursor(0,0);  // cursor 0,

    for(i=0;i<2;i++) {
      lcdInput[i] = Serial.read();
    }
    if(lcdInput[0] == 'L') {
      lcd.print("Lightning ");      
      lightData = lcdInput[1];
      light = 255 / lightData;
      analogWrite(ledPin, light);
      lcd.print(light);

This is the code. And lets say, I sent L5 from serial.
this should divide 255 to 5 and the result should be 51.

But I always keep getting 4. If I convert the light type to float
they are 4.20 to 4.70

Btw:
float light;
int lightData;
int lcdInput[2]; // Buffer

any ideas ?
Thanks

The ASCII code for 5 is decimal 53. 255 / 53 = 4.8.

Looks like your buffer is storing the integer values of the characters.

and is there a way to fix this ?

Convert the ascii values to their decimal representation. The easiest way is probably to subtract the offset between the ascii value and the decimal value.

0 starts at 48.