Go Down

Topic: Arduino splits float numbers into two( 12.67 displays 12.00 and 67.00 (Read 584 times) previous topic - next topic


What I'm trying to do is just print the entire float number but it keeps spliting. Also any ideas on how to get character by character a float number then concatenate it and display? I 'm still working on this project and so
I may post some more changes later.

Code: [Select]

float incomingByte = 0.00;
void setup()
  Serial.begin(9600);//Prepare serial port for use
  Serial.print("Enter floating point between 1000 to -1000:\n");
void loop()
  if (Serial.available() > 0)
   incomingByte = Serial.parseInt();

   if(incomingByte > 1000 || incomingByte < -1000)
   Serial.print("Sorry this numebre is out of range\n");
   Serial.print("Try again.\n");
   //incomingByte = Serial.parseInt();
   Serial.println(incomingByte); //without this there is no decimal point
  delay(500);//So serial port isn't overwhelmed.


Look at the documentation for Serial.parseInt() : it stops at the first non-digit character. There is also a parseFloat() function that may work for your case.


thank you, and yes I looked  and ended up using
Code: [Select]

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131