Decimal point in serial communication

I'm learning serial communication from PC to Uno. My circuit simply has an LED & limiting resistor connected to digital pin 9. If I enter 55 in the serial monitor the Uno turns on the LED and tells me that I entered 55. The code below works for that. If I change the code to look for 5.5, i.e. I put a decimal in the number the code fails. I receive two responses in the serial monitor - each tells me that my number is 5. How can I get the Uno to recognize a decimal point?

float myNumber;
int ledPin=9;

String msg="Please Enter Your Number:";
String msg2="Your Number Is: ";

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(msg);
while (Serial.available()==0){
  
}
myNumber=(Serial.parseInt());
Serial.print(msg2);
Serial.println(myNumber);

if(myNumber==55)
digitalWrite(ledPin, HIGH);
}

In the more general case when you want to handle a line input and parse it yourself, have a look at Serial Input Basics to handle this in a good asynchronous way

Attention to detail is what it takes :slight_smile: Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.